W
W. eWatson
It's been a very long time since I've written a C program. The one below
writes a few items to a text file. I've inserted an fopen with an "a" to
see if I could somehow append to a file by running the program twice.
That doesn't work, so what will?
#include <stdio.h>
int main()
{
FILE *myfile;
/* create a new file if it does not exist.*/
myfile = fopen("outfile.txt","w");
if (myfile != NULL) fopen("outfile.txt","a"); /* append */
fprintf(myfile,"%s","This is just an example\n"); /* writes message */
fprintf(myfile,"%s %f, %i ", "data output:", 3.14152965*0.5, 12345);
fclose(myfile); /*done!*/
printf("\nFile written.\n");
printf("Press Enter key to exit.\n");
getchar(); /* pause and wait for key */
return (0);
}
writes a few items to a text file. I've inserted an fopen with an "a" to
see if I could somehow append to a file by running the program twice.
That doesn't work, so what will?
#include <stdio.h>
int main()
{
FILE *myfile;
/* create a new file if it does not exist.*/
myfile = fopen("outfile.txt","w");
if (myfile != NULL) fopen("outfile.txt","a"); /* append */
fprintf(myfile,"%s","This is just an example\n"); /* writes message */
fprintf(myfile,"%s %f, %i ", "data output:", 3.14152965*0.5, 12345);
fclose(myfile); /*done!*/
printf("\nFile written.\n");
printf("Press Enter key to exit.\n");
getchar(); /* pause and wait for key */
return (0);
}