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]);
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.