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;
}
相关推荐
ctlover1 小时前
排序与查找算法详解
开发语言·python
YYYing.1 小时前
【C++进阶系列 (七)】C++ RTTI 深度剖析:从 typeid 到 dynamic_cast 的底层之旅
开发语言·c++·c/c++·rtti
shirsl1 小时前
算法 Day 5 树 / 二叉树 + DFS
数据结构·python·算法
木子算法2 小时前
非凸、离散、还耦合:论文里的求解方法是一条四步流水线
人工智能·算法·目标跟踪
虚无的纽扣2 小时前
【力扣刷题】第二天:无重复字符的最长字串、移动零问题
算法·leetcode·排序算法
多弗朗皮卡丘2 小时前
数据结构9:排序算法
c语言·数据结构·排序算法
张祥6422889042 小时前
牛顿迭代法求解开普勒方程:从RTKLIB源码到数值分析
人工智能·算法·机器学习
Niuguangshuo2 小时前
论文解读:Deep Speech 2,工业级英中端到端 ASR 系统报告
算法·音视频·语音识别
nvvas2 小时前
Java 入门(四):数组——数据的集合管理
java·开发语言
钓鱼的肝2 小时前
csp-j-s总结(2)
c++·经验分享·笔记·算法·青少年编程