命令行参数实现10万行小字典程序并输出查找时间

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++;
    }

}

二:编译后命令提示符窗口打开
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐维康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值