怎么用C语言写个程序找出两个英文句子中相同的英文单词
关注:284 答案:3 手机版
解决时间 2021-02-01 06:34
提问者怪咖
2021-01-31 22:50
怎么用C语言写个程序找出两个英文句子中相同的英文单词
最佳答案
二级知识专家单剑走天涯
2021-02-01 00:09
一个示范程序大致如下:
#include
#include
#include
int main(int argc, char **argv)
{
char s1[] = "This is test sentence, find all duplicated words.";
char s2[] = "Just a test for finding duplication words.";
size_t len_s1 =0;
char *s_dup = NULL;
char* pch = NULL;
char* psubstr = NULL;
len_s1 = strlen(s1);
s_dup = (char*)malloc(len_s1 * sizeof(char));
if (s_dup == NULL)
{
fputs("Memory allocating error", stderr);
}
strncpy(s_dup, s1,len_s1);
pch = strtok (s_dup, " ,.");
while (pch != NULL)
{
psubstr = strstr(s2, pch);
if (psubstr != NULL)
printf ("--->%s\n",pch);
pch = strtok (NULL, " ,.");
}
free(s_dup);
return 0;
}
全部回答
1楼失心瘋
2021-02-01 01:50
一个示范程序大致如下:
#include
#include
#include
int main(int argc, char **argv)
{
char s1[] = "This is test sentence, find all duplicated words.";
char s2[] = "Just a test for finding duplication words.";
size_t len_s1 =0;
char *s_dup = NULL;
char* pch = NULL;
char* psubstr = NULL;
len_s1 = strlen(s1);
s_dup = (char*)malloc(len_s1 * sizeof(char));
if (s_dup == NULL)
2楼魔法小仙子
2021-02-01 00:37
如果不考虑效率问题的话,
可以定义两个字符串,赋值成两个英文句子,
用两个嵌套for循环,一个单词一个单词的比较
我要举报
如以上信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
推荐资讯
大家都在看