这就是为什么当我在输出中显示字符串时我有所有单词但在最后一行有一个奇怪的符号,一个 ASCII 随机符号的代码......
我的目标是将所有要用它操作的单词保存在一个字符串中。
例如我有这个文件:
Mario
Paul
Tyler
如何保存字符串中的所有单词?
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int l,i=0,j=0,parole=0;
char A[10][10];
char leggiparola;
char testo[500];
FILE*fp;
fp=fopen("parole.txt","r");
if(fp!=NULL)
{
while(!feof(fp))
{
fscanf(fp,"%c",&leggiparola);
printf("%c", leggiparola);
testo[j]=leggiparola;
j++;
}
}
fclose(fp);
printf("%s",testo);
return 0;
}
最佳答案
关于c - 如何在字符串中保存文本文件的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41465525/