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);

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 meeting, networking, learning, and sharing knowledge.