从文本文件中读取多个字符串(空格或者换行符隔开),用链表存储,要求输入一个子串,在结点中的单词(字符串中)查找子串,以及在相邻字符子串中查找子串,返回子串所在单词的位置,以及从该单词的第几个位置开始。
例子:
I->love->you
输入子串ove,输出2
输入子串vey,输出2 3
输入子串hello,输出fail
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct word{
char wrd[20]; //单词内容
int num;
struct word *next;
}word;
void readFile(word *L)
{
char temp[20];
int num=1;
word *newWrd,*curr=L;
FILE *fp;
fp=fopen("test.txt","r");
while(!feof(fp))
{
fscanf(fp,"%s",temp);
newWrd=(word*)malloc(sizeof(word));
newWrd->next=NULL;
strcpy(newWrd->wrd,temp);
newWrd->num=num++;
curr->next=newWrd;
curr=curr->next;
}
}
void find(word *L,char *S)
{
word *cur=L->next;
int i=0,j=0,k=0;
while(cur)
{
k++;
fo