我正在尝试从 duom.txt 文件中读取文本并将每个字符存储到数组中。但我没有得到正确的答案。我的代码有什么问题?
# include <stdio.h>
# include <stdlib.h>
int main()
{
FILE *in;
char ch,str[100],cw;
int j,i = 0;
in=fopen("duom.txt","r");
if(in){
while(!feof(in)){
ch=getc(in);
str[i] = ch;
i++;
}
}
for(j=0;j<i;j++){
printf("%c",str[i]);
}
printf("\n");
fclose(in);
system("pause");
return 0;
}
duom.txt 文件:
My name is Lukas