运行这个程序时,在同目录下新建一个名为123.txt的文本,并将depend on your background are two table containing problem the digit must be separated into groups of three by commas so if you are new to then you may prefer start with get feel for the different type difficult of our problem复制到123.txt文本中,在程序结束时,可以打开生词本.txt,和历史测试结果.txt。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    system("title 背单词软件");
    system("color f0");
    system("date /T");
    system("TIME /T");
    printf("\n\n\n\n\n\n");
    printf("\t\t\t\t\t~********* 25.背单词软件 **********~\n");
    printf("\n\n\n\n");
    printf("\t\t\t\t\t~**** 制作者: Keven 2018年3月 *****~\n");
    printf("\n\n\n\n");
    printf("\t\t\t\t\t~******** 按任意键进入程序 ********~\n");
    printf("\n\n\n\n\n\n\n");
    system("pause");
    system("CLS");
    srand(time(NULL));
    FILE *fp; 
    int count=0,n,suiji,x=0,a[5],hao;
    char sum[100000][20],word[5][20],Word[20],minling[100];
    memset(sum,0,sizeof(sum));
    memset(minling,0,sizeof(minling));
    //从文件读入
    fp=fopen("123.txt","r");//只读
    while (fscanf(fp,"%s",Word)==1)
    strcpy(sum[count++],Word);
    while (1)
    {
        x=0;
        memset(word,0,sizeof(word));
        memset(a,0,sizeof(a));
        for (int i=0;i<5;i++)
        {
            suiji=rand()%count;
            for (int j=0;j<x;j++)
            {
                if (a[j]==suiji)
                {
                    i--;
                    goto a;
                }
            }
            a[x++]=suiji;
            strcpy(word[i],sum[suiji]);
            a:;
        }
        printf("请记忆下面的单词:\n");
        for (int i=0;i<x;i++)
        printf("%d %s\n",i+1,word[i]);
        printf("----------菜单-----------\n"); 
        printf("输入1将上述某个单词加入到生词本中\n输入2再记忆5个单词\n输入3查看生词本\n输入4清空生词本\n输入0结束记忆\n");
        printf("-------------------------\n请输入指令:"); 
        c:;
        //此处用char类型数组,便于判断命令是否正确 
        scanf("%s",minling);
        if (strlen(minling)>1)
        {
            printf("命令错误,请重新输入命令:");
            goto c;
        }
        if (strlen(minling)==1)
        {
            if (minling[0]!='0'&&minling[0]!='1'&&minling[0]!='2'&&minling[0]!='3'&&minling[0]!='4')
            {
                printf("命令错误,请重新输入命令:");
                goto c;
            }
        }
        if (minling[0]=='1')
        {
            d:;
            printf("(输入0返回上一步)请输入需要加入生词本单词的序号:"); 
            scanf("%d",&hao);
            if (hao==0)
            {
                system("CLS");
                continue;
            }
            //回到生词本.txt头部 
            fp=fopen("生词本.txt","r");//只读 
            while (fscanf(fp,"%s",Word)==1)
            {
                if (strcmp(Word,word[hao-1])==0)
                {
                    printf("该单词之前已经存入生词本\n\n");
                    goto b; 
                }
            }
            printf("该单词已存入生词本\n\n");
            fp=fopen("生词本.txt","a+");//修改 
            fprintf(fp," %s",word[hao-1]);
            fclose(fp);
            //每次以a+方式打开,需要关闭文件便于下次重新读取 
            b:;
            goto d; 
        }
        else if (minling[0]=='2')
        system("CLS");
        else if (minling[0]=='3')
        {
            system("CLS");
            printf("您的生词本如下:\n"); 
            //回到生词本.txt头部 
            fp=fopen("生词本.txt","r");//只读
            //输出生词本 
            while (fscanf(fp,"%s",Word)==1)
            puts(Word);
            printf("\n"); 
            continue;
        }
        else if (minling[0]=='4')
        {
            fp=fopen("生词本.txt","w+");
            system("CLS");
            printf("生词本已清空\n\n"); 
        }
        else if (minling[0]=='0')
        break;
    }
    system("CLS");
    printf("您的生词本如下:\n\n"); 
    //回到生词本.txt头部 
    fp=fopen("生词本.txt","r");//只读 
    //输出生词本
    while (fscanf(fp,"%s",Word)==1)
    puts(Word);
    printf("\n"); 
    printf("下面您将进行一个生词测验\n\n"); 
    system("PAUSE");
    system("CLS");
    //OJ系统 
    char ch;//输入 
    count=0;//统计生词本中单词个数 
    int trues=0,flag;//统计正确数 
    //回到生词本.txt头部 
    fp=fopen("生词本.txt","r");//只读
    while (fscanf(fp,"%s",Word)==1)
    {
        flag=1;
        e:;
        suiji=rand()%strlen(Word); 
        for (int i=0;i<strlen(Word);i++)
        {
            if (i!=suiji)
            printf("%c",Word[i]);
            else
            printf("_");
        }
        printf("请输入单词中缺少的字母:");

        getchar();//为什么要getchar()?????

        scanf("%c",&ch);
        printf("%c",ch);
        if (ch==Word[suiji])
        printf("答对了!\n");
        else
        {
            printf("答错了!\n再试试看\n");
            flag=0;
            goto e; 
        }
        if (flag==1)//为避免重复计数,引入flag判断 
        trues++;
        count++; 
    }
    printf("\n通过对生词本中单词的测试,您的正确率为%.2lf%%\n",trues*1.0/count*100); 
    printf("\n----------感谢使用本程序,欢迎下次使用----------\n");
    //将测试时间,日期和数据存入促使结果,txt,并在结束时打开两个txt文本 
    system("date /T >> 测试结果.txt");
    system("TIME /T >> 测试结果.txt");
    fp=fopen("测试结果.txt","a+");//修改 
    fprintf(fp,"本次生词本中单词的正确率为%.2lf%%\n\n",trues*1.0/count*100); 
    fclose(fp);//关闭
    printf("您的生词本已打开\n"); 
    system("生词本.txt");
    printf("您的测试结果的历史数据已打开\n"); 
    system("测试结果.txt"); 
    system("PAUSE");
}