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;
}
相关推荐
NiNi_suanfa1 小时前
【Qt】Qt 批量修改同类对象
开发语言·c++·qt
小糖学代码2 小时前
LLM系列:1.python入门:3.布尔型对象
linux·开发语言·python
Data_agent2 小时前
1688获得1688店铺详情API,python请求示例
开发语言·爬虫·python
妖灵翎幺2 小时前
C++ 中的 :: 操作符详解(一切情况)
开发语言·c++·ide
风筝在晴天搁浅3 小时前
代码随想录 718.最长重复子数组
算法
kyle~3 小时前
算法---回溯算法
算法
Halo_tjn3 小时前
虚拟机相关实验概述
java·开发语言·windows·计算机
star _chen3 小时前
C++实现完美洗牌算法
开发语言·c++·算法
周杰伦fans3 小时前
pycharm之gitignore设置
开发语言·python·pycharm
hzxxxxxxx3 小时前
1234567
算法