C //练习 5-4 编写函数strend(s, t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。

C程序设计语言 (第二版) 练习 5-4

练习 5-4 编写函数strend(s, t)。如果字符串t出现在字符串s的尾部,该函数返回1;否则返回0。

注意:代码在win32控制台运行,在不同的IDE环境下,有部分可能需要变更。
IDE工具:Visual Studio 2010
代码块:
c 复制代码
#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;
}
相关推荐
無限進步D21 小时前
Java 运行原理
java·开发语言·入门
是苏浙21 小时前
JDK17新增特性
java·开发语言
阿里加多1 天前
第 4 章:Go 线程模型——GMP 深度解析
java·开发语言·后端·golang
likerhood1 天前
java中`==`和`.equals()`区别
java·开发语言·python
IronMurphy1 天前
【算法三十九】994. 腐烂的橘子
算法
zs宝来了1 天前
AQS详解
java·开发语言·jvm
Tomhex1 天前
C语言内存安全防护指南
c语言
Ares-Wang1 天前
算法》》旅行商问题 TSP、7座桥问题 哈密顿回路 深度优先 和 宽度优先
算法·深度优先·宽度优先
Liqiuyue1 天前
Transformer:现代AI革命背后的核心模型
人工智能·算法·机器学习
WolfGang0073211 天前
代码随想录算法训练营 Day34 | 动态规划 part07
算法·动态规划