当前位置:首页 » 编程语言 » 单词查询系统c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

单词查询系统c语言

发布时间: 2022-04-29 07:05:13

1. 一个c语言程序,单词测试系统需要设计哪些方面

编程语言:C语言

程序目标:从一个txt文件中读取字符,识别其中每一个英文单词。

数据结构:链表,结构体

基本思路:最外层循环判断条件是文件中有数据读取,每次从文件中读取一个字符,判断是否是字母,每次读取到空格就说明一个单词的结束,然后把得到的单词插入到链表中,链表中每一个节点存储

一个单词,并记录该单词的频数,插入规则是,有该单词,则增加频数,否则插入到链表。最后从链表中选取频数最大的是个节点输出。分析结论:第一张图显示的CPU消耗时间主要是在前面部分,这跟我的代码是相对应的,在主函数的调用过程中,前面部分是读取数据,构建相关数据结构,因而资源消耗大。第二张图显示,creatlist

函数中分为子函数和不包含子函数对资源的消耗,不包含子函数的独占样本百分百要多,说明creatlist函数在算法上比creatnode函数要复杂一些,这也跟处理该问题的主体算法思路有关。第三章图显

示的creatlist函数的消耗资源最多,其次是库函数strcmp,因为creatlist函数在构建的时候,要判断是插入节点还是直接增加某个节点的频数,因而需要搜素链表,所以要消耗很多资源,在搜索过程

2. 用c语言编写一个背单词的系统 大神们帮帮忙啊!!!!

Y花点真的Money吧,这也算一个较大的程序吧

3. 写一条查找单词数的C语言

#include <stdio.h>
main()
{
char c[10],d[10];
int i=0,a=0,p=1,k=0;
printf("输入一个单词,以空格结束\n");
while(i<10)
{c[i]=getchar();
i++;
if (c[i-1]==' ')
{printf("请输入文章,以0结束\n");break;}}
show:
while(a<10)
{ d[a]=getchar();
if(d[a]=='0')
break;
if (d[a]==' ')
{ i=0;
while ((i<=9)&&(c[i]==d[i]))
i++;
if(i==a+1)
{ p++;k++;a=0;
goto show;}
else
{k++;
a=0;
if(k<=1000)
goto show;}

}
a++;
}
printf("一共有%d个",p);
}

这里只给出有几个,位置就自己加一下吧,我也刚学

4. 查询单词 C语言如何实现

你一个一个字符的来判断.你可以设定一个变量来表示一个单词的开始和结束.flag=0时是没有单词,当flag=1时一个单词的开始.那flag=1即单词开始时扫描的是字符继续下个字符的,如果是非字符flag=0;到下个字符开始是flag=1;那一个单词的开始到结束就是一个单词了,你可以设定一个变量来记录单词的个数.

5. 用C语言编写设计一个简易的星期单词查询系统。即:从键盘输入星期几的数字,显示出相应的英语单词。

摘要 Problem G: C语言实验——输入数字星期,输出英文(选择结构-switch)

6. 用C语言写:检索英文单词程序

#include<stdio.h>
#include<string.h>
#define MAX_size 1000
int flag=1,degree=0;
void Index(char str[],char word[],int position[])
{
int i,len_str,len_word,pos_str,pos_word,k=0,word_number=0;//word_number代表短文中单词的个数
len_word=strlen(word);
len_str=strlen(str);
for(i=0;i<len_str;)
{
while(str[i]==' ')
i++;
word_number++; //单词个数加一
for(pos_str=i,pos_word=0;pos_str<len_str && pos_word<len_word;pos_str++,pos_word++)
{
if(str[pos_str]!=word[pos_word])
break;
}
if(pos_word==len_word && (str[pos_str]=='\0'|| str[pos_str]==' ' )) //表明找到相等的单词
{
position[k++]=word_number;
degree++; //相等的次数加1
flag=0;
}
else
{
while(str[pos_str]!=' ' && pos_str<len_str)
pos_str++;
}
i=pos_str;
}
}
void main()
{
char str[MAX_size],word[20];

int position[100],i;
printf("请输入一行英文短文: \n");
gets(str);
printf("请输入要检索的单词: \n");
gets(word);
Index(str,word,position);
if(flag)
printf("您输入的单词不在短文中。\n");
else
{
printf("您输入的单词在短文中,它共出现 %-d 次\n",degree);
printf("出现的位置为: \n");
for(i=0;i<degree;i++)
printf("第%-2d个单词\n",position[i]);
}
}//未考虑逗号,若要考虑则加几个判断条件即可

7. 用c语言编写背单词系统要求背单词和测验,浏览单词

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
structword
{
charenglish[30];
charchinese[100];
intcount;/*记录背单词的正确次数*/
}dic[4000];
chargetChoice()
{
charstr[10];
gets(str);
while(strlen(str)==0)
{
printf("输入为空,请重新输入:");
gets(str);
}
returnstr[0];
}

intmain()
{
FILE*fp;
charch,line[100];
intkong,i,count=0,j=0,end=0,k=0;
intlast_process=0;

if((fp=fopen("cet4.txt","r"))==NULL)
{
printf("cannotopenthetxt!!! ");
exit(0);
}

/*读取所有单词*/
while(fgets(line,sizeof(line),fp)!=0)
{
/*每一行记录的格式【单词中文正确数】*/


/*读取单词*/
j=0;
for(i=0;i<line[i]!='';i++)
{
dic[count].english[j]=line[i];
j++;
}
dic[count].english[i]='';

/*特殊处理,如果这个字段是自定义的上次进度标记,则记下进度,假如进度标记是#last_process#*/
if(strcmp(dic[count].english,"#last_process#")==0)
{
last_process=atoi(line+i+1);
continue;
}

/*读取中文*/
j=0;
for(i=kong+1;i<line[i]!='';i++)
{
dic[count].chinese[j]=line[i];
j++;
}
dic[count].chinese[j]='';

/*正确数*/
dic[count].count=atoi(line+i+1);

count++;
}
fclose(fp);

/*打印下读取的信息*/
printf("单词数:%d 上次背到第%d个单词 ",count,last_process);

/*while*/
/*这里背单词策略,可以根据count来判断单词熟悉度,该值越大表示越熟悉*/
/*负数表示记错了的次数,错的越多,负的越大*/
i=last_process;
while(ch!=0)
{
//可根据需要排序单词,排序依据是count字段大小
puts(" 1.随机20个单词测试 ");
puts(" 2.强化记忆 ");
puts(" 前一个(P)后一个(N)收藏(C)结束浏览(M)");
while(ch!=0)
{
ch=getChoice();
if(ch=='P'||ch=='p')
{
i=(last_process+count-1)%count;
printf("%s ",dic[i].english);
printf("%s ",dic[i].chinese);
}

if(ch=='N'||ch=='n')
{
i=(last_process+1)%count;
printf("%s ",dic[i].english);
printf("%s ",dic[i].chinese);
}
elseif(ch=='C'||ch=='c')
{
printf("已经加入单词本");
}

if(ch=='M'||'m')
{
break;
}
}
}

/*程序退出*/
last_process=i;
if((fp=fopen("cet4.txt","w"))==NULL)
{
printf("cannotopenthetxt!!! ");
exit(0);
}
/*把单词进入重新写入单词文件*/
for(i=0;i<count;i++)
{
fprintf(fp,"%s%s%d ",dic[i].english,dic[i].chinese,dic[i].count);
}
fprintf(fp,"#last_process#%d",last_process);
fclose(fp);

return0;
}

大致这样子,懒得写了~~~有需要可讨论

8. C语言 单词检索程序

=====================================
问题补充:二楼的是死循环运行不了啊
=====================================
实在抱歉,之前疏忽了,现在已经改好了,再试一下吧:)

=====================================
问题补充:二楼的幸苦了,仔细看了一下你的,好像有点出入,不是自己输入文章,是打开已有文章。还得麻烦你稍稍修改下。谢谢哈
=====================================
根据你的要求,又改了一版,现在已经改好了,再试一下吧:)
给:
#include<stdio.h>
#include<string.h>
#define MAX_size 1000
int flag=1,degree=0;
void Index(char str[],char word[],int position[])
{
int i,len_str,len_word,pos_str,pos_word,k=0,word_number=0;//word_number代表短文中单词的个数
len_word=strlen(word);
len_str=strlen(str);
for(i=0;i<len_str;i++)
{
while(str[i]==' '||str[i]==','||str[i]=='.')
i++;
word_number++; //单词个数加一
for(pos_str=i,pos_word=0;pos_str<len_str && pos_word<len_word;pos_str++,pos_word++)
{
if(str[pos_str]!=word[pos_word])
break;
}
if(pos_word==len_word && (str[pos_str]=='\0'|| str[pos_str]==' '||str[pos_str]==','||str[pos_str]=='.')) //表明找到相等的单词
{
position[k++]=word_number;
degree++; //相等的次数加1
flag=0;
}
else
{
while(str[pos_str]!=' '&&str[pos_str]==','&&str[pos_str]=='.'&& pos_str<len_str)
pos_str++;
}
i=pos_str;
}
}
void main()
{
char str[MAX_size],word[20],ch;
int position[100],i;

int k=0;
FILE *fp;

if((fp=fopen("a.txt","r"))!=NULL)
{
while(1)
{
ch=fgetc(fp);
if(ch==EOF) break;

str[k]=ch;
k++;
}
}

printf("请输入要检索的单词: \n");
gets(word);
Index(str,word,position);
if(flag)
printf("您输入的单词不在短文中。\n");
else
{
printf("您输入的单词在短文中,它共出现 %-d 次\n",degree);
printf("出现的位置为: \n");
for(i=0;i<degree;i++)
printf("第%-2d个单词\n",position[i]);
}
fclose(fp);
}

9. 输入前几个字母就能找出这个单词的模糊查找,用c语言如何编程

给你个思路,每次查找都至少找到5个结果才结束,一个单词,先获取单词部分,根据输入长度截取单词,只要匹配就可以。
在高级点一个单词,先获取单词部分,再遍历单词,按照输入的长度 每次截取那么长再比较,
如果你会连接数据库就不用这些代码了,直接用LIKE %%。

10. 用C语言编程,如何查找一段文字(有英有汉)中的某些英文单词,并统计其数量

//search.c
#include <stdio.h>
#include <conio.h>
main()
{
FILE*fp;
char key[20],ch;
int i,l,num=0;
if((fp=fopen("d:\\word.dat","w+"))==NULL)
{ printf("can not open file");
getch();
exit(0);
}
printf("输入文章(按#键结束)_\n ");
do{
ch=getchar();
fputc(ch,fp);
}while(ch!='#');
getchar();
printf("\n输入要查询的关键字_ ");
gets(key);
rewind(fp);
ch=fgetc(fp);
while(ch!=EOF)
{
if(ch==key[0])
{
l=strlen(key);
for(i=1;i<l;i++)
{
ch=fgetc(fp);
if(ch!=key[i]) break;
}
num++;

}
ch=fgetc(fp);
}
printf("共计: %d (%s)\n",num,key);
getch();
}