Reputation: 49
Good evening people. I am trying to print strings into a result file, however things aren't going very well. For example the contents of my data file are:
Hello, today
is a
Good Day
What is going
On here?
and the result file turns out to show:
On here?
g
This is my printing function:
void print(char B[])
{
printf("%s", B); //NOTE; this string represents a line of data file and works!
FILE *wfile;
if ((wfile = fopen("result.txt","w")) == NULL){
printf("File did not open!!!/n");
exit(1);
}
fprintf(wfile, "%s", B);
}
I am at a loss guys, any kind of input is greatly appreciated.
Upvotes: 0
Views: 512
Reputation: 49
Thanks to the commenters, I have realised that instead of
if ((wfile = fopen("result.txt","w")) == NULL)
I had to change the "w" to "a" since I want to append strings to the file
if ((wfile = fopen("result.txt","a")) == NULL)
Upvotes: 1