Dear All,
I am trying to write to a file as below. But my file shows empty what could be wrong here?

const char *dataFileName = "data.dat";
FILE *ftdata = fopen(dataFileName,"a+");
fwrite("TEST",1,2,ftdata);

Recommended Answers

maybe you need to try to close the file to save what you wrote

Jump to Post

All 2 Replies

maybe you need to try to close the file to save what you wrote

As said above, you need to call fclose(ftdata);. To prevent future headaches, your third argument (count) should be set to 4 instead of 2 if you want to fully print "TEST".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.