FILE * fPointer;
float amount = 3.1415;
fPointer =fopen("vending.txt","w");
fprintf(fPointer, amount);
printf("The file has been created for the first time and we added the value %f", amount);
fclose(fPointer);
I am trying to save a float number to a text file but when I try to run this code it triggers a compiling errors because the function fprintf
expects the second parameter to be an array of characters so how can I convert my float to a string so I can pass it, I have a C# background where something like .toString()
is possible so is there any thing like that in C to directly cast a float to a string?