C//练习5-4编写函数strend(s,t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。
- 游戏开发
- 2025-08-06 07:30:01

C程序设计语言 (第二版) 练习 5-4 练习 5-4 编写函数strend(s, t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。 注意:代码在win32控制台运行,在不同的IDE环境下,有部分可能需要变更。 IDE工具:Visual Studio 2010
代码块: #include <stdio.h> #include <stdlib.h> #include <string.h> int strend(char *s, char *t){ int len1 = strlen(s); int len2 = strlen(t); for(int i = len2 - 1, j = len1 - 1; i >= 0; i--, j--){ if(t[i] != s[j]){ return 0; } } return 1; } int main(){ char s[] = "hello"; char t[] = "llo"; printf("%d\n", strend(s, t)); system("pause"); return 0; }
C//练习5-4编写函数strend(s,t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。由讯客互联游戏开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“C//练习5-4编写函数strend(s,t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。”
上一篇
docker容器互通方式