electroRF
Member
Hi,
I tested this example of writing to a file and then to a buffer:
I have a question please:
With the above code, nothing is written to mybuffer.
Is it because fflush resets the counter of the file's size? (WITHOUT deleting its content, i.e. test remains written)
Thank you very much.
I tested this example of writing to a file and then to a buffer:
C:
/* fflush example */
#include <stdio.h>
char mybuffer[80];
int main()
{
FILE * pFile;
pFile = fopen_s(&pfile, "example.txt","w+");
if (pFile == NULL) perror ("Error opening file");
else {
fputs ("test",pFile);
fflush (pFile); // flushing or repositioning required
fgets (mybuffer,80,pFile);
puts (mybuffer);
fclose (pFile);
return 0;
}
}
I have a question please:
With the above code, nothing is written to mybuffer.
Is it because fflush resets the counter of the file's size? (WITHOUT deleting its content, i.e. test remains written)
Thank you very much.
Last edited: