求助: c 程序 在VC++ 环境下运行错误

2025-05-22 05:44:45
推荐回答(1个)
回答1:

你这题 好像并没有把文件中的数据读到结构体word中啊

我先做着 一会儿再把答案发过来

#include
#include
#include
void rf();

struct ce
{
char ch[30];
char en[30];
}ctoe[20];

int line=0;
void main()
{
rf();
}

void rf()
{
int sum=0;
int i,j;
char c[30];
FILE *fp;
fp=fopen("word.txt","r");
if(fp==NULL)
{
printf("Can't open file!");
exit(0);
}
while((i=fgetc(fp))!=EOF)
{
if(fgetc(fp)=='\n')
{
line++;
}
}
rewind(fp);
for(i=0;i<=line;i++)
{
fscanf(fp,"%s%s",&ctoe[i].ch,&ctoe[i].en);
}
for(i=0;;i++)
{
if(i<=line)
{
// srand((unsigned)time(NULL));
// j=rand()%8+1;
printf("请翻译下面单词:\n");
printf("%s\n",ctoe[i].ch);
scanf("%s",&c);
if(strcmp(c,ctoe[i].en)==0)
{
printf("\n恭喜你答对啦! 现在我们进行下一题吧!\n\n");
sum=sum+1;
}
else
{
printf("\n很遗憾,不过要加油呀!\n\n");
printf("正确的答案是:%s\n",ctoe[i].en);
}
}
else
{
printf("全文翻译完毕!\n");
printf("你的得分是: %d 分\n",sum);
exit(0);
}
}
fcloseall();
}
不知道是不是你要的那种结果