Answer the question
In order to leave comments, you need to log in
Passing argument 1 of 'fwrite' makes pointer from integer without a cast?
Hello. There is an integer type variable with value 7. I am trying to write this variable to a text file with the fwrite() function;
Here is the code:
int size = 7;
FILE *fp;
fp = fopen("saves.txt", "w");
fwrite(size, 1, sizeof(size), fp);
fclose(fp);
Answer the question
In order to leave comments, you need to log in
That you didn't bother to read the description of the fwrite function .
The first parameter must be a pointer to the data being written, the second is the size of a single data element, and the third is the number of these elements.
The fwrite() function writes count objects—each object is size characters long—to the stream specified by stream from the character array specified by buf. That is, instead of size, you must pass a pointer to the buffer, from where fwrite will copy the characters to the file.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question