Reputation: 11
I am trying to save my number in a file but the program keeps crashing:
include stdio.h
include mpir.h
int main(void){
mpf_set_default_prec(32); //Default precision for floating points
mpf_t my_number;
mpf_init_set_str(my_number, "5.12345e0", 10); //Set my_number to 5.123 with decimal base (10)
FILE *f;
f = fopen("some.txt", "w");
gmp_printf("Printed number to screen: %.*Ff \n", 32, my_number);
//Everything works until I try to save it to file:
gmp_fprintf(f, "My saved number is: %.*Ff \n", 32, my_number);
fclose(f);
return 0;
}
Instead of fprintf i tried:
gmp_fscanf(f, "%F", &zbroj)
mpz_out_str(f, 10, zbroj)
sprintf(f, "%F", zbroj)
Upvotes: 1
Views: 243
Reputation: 11
It seems that there was something wrong with my x64 build. I compiled MPIR again (this time x32) and put files to VS directory and it worked.
My guess is that there are special instructions for building x64 that I did not follow :\
Btw. I used mpf_out_str(f, 10, 0, var);
Where f is pointer to file, 10 is base, 0 means maximum precision and var is variable that will be saved.
Upvotes: 0