/*使用方法可以建立英语库,每次可建立100个单词*/
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef strUCt
{
char cha[50];
char eng[50];
}CTOE;
void writefile();
void practicec();
int main()
{
char id;
FILE *fp;
if((fp=fopen("g:\\ctoe.txt","r"))==NULL)/*检测文件是否成在如无文件测建立*/
{
printf("not file!");
clrscr();
writefile();/*建立函数*/
}
do
{
clrscr();
printf(" __________________________________\n");
printf(" 0.建立英语库 1.进入练习 2.退出 \n");
printf("__________________________________\n");
id=getch();
switch(id)
{
case '0':writefile(); break;/*建立文件*/
case '1':practicec(); break;/*进入测试题*/
}
}while(id!='2');
fclose(fp);
}
void writefile()
{
CTOE ctoe[100];
FILE *fp;
int i,count=0;
do
{
printf("%dinput china:",count+1);
scanf("%s",ctoe[count].cha);
printf("%dinput english:",count+1);
scanf("%s",ctoe[count].eng);
count++;
}while(count<100);
fp=fopen("g:\\ctoe.txt","w");
for(i=0; i<count; i++)
fprintf(fp,"%s %s\n",ctoe[i].cha,ctoe[i].eng);
fclose(fp);
}
void practicec()
{
CTOE ctoe[100];
char ieng[20];
int num=100,rn=0,orn,grade=30;
int score=0;
FILE *fp;
int i;
fp=fopen("g:\\ctoe.txt","r");
for(i=0; i<100; i++)
fscanf(fp,"%s %s",ctoe[i].cha,ctoe[i].eng);
do
{
for(i=0; i<grade; i++)
{
do
{
orn=rn;
rn=random(num);
}while(rn==orn);
printf("%d\t%s\n",i,ctoe[rn].cha);
printf("请翻译单词:");
scanf("%s",ieng);
if(strcmp(ieng,ctoe[rn].eng))
{
printf("错误正确的应是:%s\n",ctoe[rn].eng);
}
else
{
printf("您答对了请继续!\n");
score+=1;
}
}
if(score>=grade-1)/*判断是否合格合格进入下一级*/
{
grade+=10;
clrscr();
printf("非常好您过关了按任意键进入下一级!");
clrscr();
getch();
}
else { grade=0;
clrscr();
printf("真不幸您没有过关!");
}
}while(grade);
fclose(fp);
getch();
}