英文句子比较大小c语言,怎么用C语言写个程序找出两个英文句子中相同的英文单词...

怎么用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循环,一个单词一个单词的比较

我要举报

如以上信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!

推荐资讯

大家都在看

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值