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

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:54:30
要求是:
1.通过键盘输入一篇正确的英文短文
2.将该英文短文存储在一个一维字符数组中
3.再通过键盘输入一个正确的英文单词
4.然后采用字符串匹配法在短文(一维字符数组)中进行查找
5.查找必须在短文开始位置一直到结尾,根据查找结果输出下列信息:
该单词在短文中存在还是不存在,如果该单词在短文中存在,则输出该单词在短文中出现的次数和位置
6.说明:必须采用字符串匹配算法,不能采用C语言中的字符串匹配函数

我自己写了一点,但是往后不会了
大家帮帮忙
下面是我自己写的,但是有很多问题:

#include"stdio.h"
#include"string.h"
#define LEN 2000
#define N 50
main()
{
int i=0,j,k=0,l=1;
int n=0,m=0,p=0;
char word[LEN],line1[50],*blank;
char c[30];
printf("请输入一篇英文短文:\n");
blank="\n";
gets(line1);
strcpy(word,line1);
strcat(word,blank);
while(line1[0]!='0')
{
gets(line1);
strcat(word,line1);
strcat(word,blank);
}
printf("请输入您要检索的单词:\n");
gets©;
i=j=0;
while(word[i]!='0')
{
m=0;
for(j=0;j<30;j++)
{
if(word

#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_s