Reputation: 45
I want the program to print the word hello to the text file by means of strings.
#include <stdio.h>
void main ()
{
char word[10] = {"hello"};
FILE*fp;
fp = fopen("C:\\temp\\Dictionary.txt", "w+");
fprintf(fp, word[0]);
}
Upvotes: 1
Views: 517
Reputation: 2488
You're printing first char instead of the string. And it might not be a valid format either. Correct call will be fprintf(fp, "%s", word)
. And don't forget to close file too.
Upvotes: 2