david
david

Reputation: 21

i need to take an mpir integer and output it into a char buffer

i have recently installed mpir and have the following code (c++) visual studio.

char buffer[100]
mpz_t x;

mpz_set_str(x, "7612058254738945", 10);

I would like to print x into the buffer. used to use sprint but there does not seem to be any sprint for mpir

thanks

david

Upvotes: -1

Views: 174

Answers (1)

Mohit Jain
Mohit Jain

Reputation: 30489

You can use mpz_get_str along with sprintf(%s specifier) or strcat or someother string utility.

From the same page for length of this number

To find out the right amount of space to provide for str, use mpz_sizeinbase (op, base) + 2. The two extra bytes are for a possible minus sign, and for the terminating null character.

Upvotes: 4

Related Questions