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

来源:百度知道 编辑:UC知道 时间:2024/07/04 09:32:46
#include <stdio.h>
#include<stdlib.h>
#include <time.h>
#define SIZE 100
struct word
{char chin[40];
char eng[20];
}
word[SIZE];
main()

{ int i,j,k,score=0;
FILE*fp;

if(( fp=fopen("word.txt","rb"))==NULL) /*打开文件,进行读取*/
{printf("cannot open file\n");
exit(0);
}

for(j=0;j<10;j++) /*输出10道题,进行练习*/
{ randomize();
i=rand() %100;
fseek(fp,(60*i)L,0);
fread(&word[i],sizeof(struct word),10,fp); /*读取文件*/
printf("%s",word[i].chin); /*读出汉语*/
scanf("%s",&word[j].eng); /* 输入英语*/

{ if(strcmp(word[i].eng,word[j].eng)==0) /*字符串比较*/
printf("\n恭喜你答对啦! 现在我们进行下一题吧!\n\n"),score=score+1;
else printf("\n很遗憾,不过要加油呀!\n\n"),score=score+0;
prin

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

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

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
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&#