I'm using MPIR/Ubuntu 14.04.
I have big integer that have a lot of digits, like 2^1920, and don't know how to write it into file *.txt
FILE *result;
result=fopen("Number.txt","a+");
gmp_fprintf(result,"%d",xyz);
fclose(result);
didn't work.
Are there some other options I can use?
The
gmp_printf()function (thus subsequentlygmp_fprintf()as well) requires special format specifier formpz_tobject (which I guessxyzis). You should use%Zdinstead of plain%d, that does not work. To be pedantic it's undefined behavior to use inadequate f.s. in C.If you don't need "full-featured" formatted output, then you might also take a look at
mpz_out_str(), that allows to specify base (like 2 or 10):Alternatively you might use
mpz_out_raw()function that just "dumps" the whole number as it is stored in binary format: