帮助自己巩固英语单词,一个小程序;使用fopen对txt读取数据

小程序,一时兴起

首先把单词和中文意思都放在txt文件中
使用结构体来读取单词和中文意思,声明成结构体数组,方便后期使用随机数的时候可以直接取到该单词的数据
读取数据使用fopen函数,还未彻底完善,后期会修改。

写这个程序主要是为了帮助自己记单词hhhhh,来自英语菜鸡的无奈。。。。。
上代码:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include <time.h>
#define Max 1000

struct  point_{
	char p_w[20];   //用来存储单词 
	char q_h[100];  //用来存储中文 
};

typedef struct point_ point;
 

struct Eng{
	point strs[Max];
	int len;
};
typedef struct Eng L;
void menu()
{
	printf("1.twenty time write Word\n2.nothing\n3.return the program \n");
}


int WriteDataInProgram(L *);
void print(L*); 
L* creater();
void writeWord(L *);
int  repetition(int *,int *,int );


int main ()
{
	int x;
	L *head=creater();
	if (WriteDataInProgram(head))
	{
		printf("open the file is falied  program over\n");
		return 0;
	}
	printf("place enter value in x\n");
	
	while (1)
	{
		menu();
		scanf("%d",&x);
		switch(x)
		{
			case 1:
				writeWord(head);
				break;
			case 2:
				
				break;
			case 3:
				return 0;
		}
		printf("place enter anything key\n");
		getch();
		system("cls");
	}
	free(head);
	return 0;
}


L *creater()
{
	L *head=(L*)malloc(sizeof(L));
	head->len=0;
	return head;
}

void print(L *head)
{
	int i;
	for (i=0;i<head->len;i++)
	printf("%s\t\t\t%s\n",head->strs[i].p_w,head->strs[i].q_h);
	return ;
}

int WriteDataInProgram(L *head)
{
	int i=0;
	FILE *fp=NULL;
	fp=fopen("D:/C(project)/英语单词/EnglishWord.txt","r");
	if (fp==NULL)
	{
		printf("open the file is falied\n");
		return 1;
	}
	else
	{
		while (fscanf(fp,"%s",&head->strs[i].p_w)!=EOF)
		{
			fscanf(fp,"%s",&head->strs[i].q_h);
			i++;
		}
	}
	fclose(fp);
	head->len=i;
//	print(head);
	return 0;
}

int repetition(int *temp,int *p,int num)
{
	int i=0;
	for (i=0;i<num;i++)
	{
		if (temp[i]==*p)
		return 0;
	}
	return 1;
}

void writeWord(L *head)
{
	int i,temp[20],line=0,row=0;
	double sum=0;
	char mistake[20][20];
	char word[20];
	time_t t;
	for (i=0;i<20;i++)
	{
		back:
		srand((unsigned)time(NULL));
		temp[i]=rand()%131-1;
		if (repetition(temp,&temp[i],i)==0)
		goto back;
		printf("%s\tplace enter Word\n",head->strs[temp[i]].q_h);
		scanf("%s",word);
		if (strcmp(word,head->strs[temp[i]].p_w)==0)
		{
			sum++;
		}
		else
		{
			strcpy(mistake[row],head->strs[temp[i]].p_w);
			row++;
		}
	}
	printf("you accuracy(正确率) is%lf,in all:%lf\n",sum/20,sum);
	for (i=0;i<row;i++)
	printf("mistake word are:%s\n",mistake[i]);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值