incode.txtson文件链接:https://pan.baidu.com/s/1ZNpe0bZJcMPPQYKo97Y9OQ
提取码:22br
一:代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct WordStruct
{
char english[20];
char chinese[80];
}wd;
wd allWords[120000];
int wordCount=0;
void read_data_in_file();
int main(int argc, char *argv[])
{
read_data_in_file();
int i;
char* exc = argv[1];
for(i = 0;i < wordCount;i++)//寻找数组中是否有对应解释,有的话则显示。
{
if(strcmp(exc,allWords[i].english)==0)
{
printf("the result:%s\n",allWords[i].chinese);
break;
}
}
time_t timep;
struct tm*p;
time(&timep);
p=gmtime(&timep);
printf("string time is:%d\n",p->tm_sec);
return 0;
}
void read_data_in_file(int flag)
{
FILE* fp = fopen("incode.txt","r");
char temp[50];
int i=0;
while(!feof(fp))//循环读取文本知道结尾
{
if(!feof(fp))//如果未到达文件结尾,则进行数据读取
{
//if()
fscanf(fp,"%s",temp);
strcpy(allWords[wordCount].english,temp);
fscanf(fp,"%s",temp);
strcpy(allWords[wordCount].chinese,temp);
}
if(!feof(fp))//如果未到达文件结尾,进行计数
wordCount++;
}
}
二:编译后命令提示符窗口打开