【怎么用C语言写个程序找出两个英文句子中相同的英文单词】
怎么用C语言写个程序找出两个英文句子中相同的英文单词
【怎么用C语言写个程序找出两个英文句子中相同的英文单词】
怎么用C语言写个程序找出两个英文句子中相同的英文单词
一个示范程序大致如下:
#include
#include
#include
intmain(intargc,char**argv)
{
chars1[]="Thisistestsentence,findallduplicatedwords.";
chars2[]="Justatestforfindingduplicationwords.";
size_tlen_s1=0;
char*s_dup=NULL;
char*pch=NULL;
char*psubstr=NULL;
/*makeaduplicationtoprotectthesource*/
len_s1=strlen(s1);
s_dup=(char*)malloc(len_s1*sizeof(char));
if(s_dup==NULL)
{
fputs("Memoryallocatingerror",stderr);
}
strncpy(s_dup,s1,len_s1);
/*slicethedup.string,loopthru2ndstringtocomparewordbyword*/
pch=strtok(s_dup,",.");/*modifyingifnecessary*/
while(pch!=NULL)
{
/*printf("%sn",pch);*//*debugprint*/
psubstr=strstr(s2,pch);
if(psubstr!=NULL)
printf("--->%sn",pch);
pch=strtok(NULL,",.");
}
/*releasememoryallocatedbymallocabove*/
free(s_dup);
return0;
}
如果不用指针该怎么做
①哪一部分不希望是指针?②为什么不希望是指针?C的特点之一啊?