[英]Printing to a text file in c using strings
I want the program to print the word hello to the text file by means of strings. 我希望程序通过字符串将单词hello打印到文本文件。
#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. 您正在打印第一个char而不是字符串。 And it might not be a valid format either. 而且它也可能不是有效格式。 Correct call will be fprintf(fp, "%s", word)
. 正确的调用将是fprintf(fp, "%s", word)
。 And don't forget to close file too. 并且不要忘记关闭文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.