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;
}
相关推荐
大鱼>3 分钟前
AI+快递分拣:视觉识别+自动分拣+异常检测
人工智能·深度学习·算法·机器学习
想要成为糕糕手5 分钟前
238. 除了自身以外数组的乘积 — 面试向深度解析
javascript·算法·面试
玖玥拾6 分钟前
C# 语言进阶(十三)网络 DLL 库分层设计
服务器·开发语言·网络·网络协议·c#
2601_9498163512 分钟前
C++内存对齐与结构体填充深度精讲:底层规则、内存裁剪、适配优化与工程避坑
开发语言·arm开发·c++
浩瀚地学17 分钟前
【面试算法笔记】0105-数组-螺旋矩阵
java·开发语言·笔记·算法·面试
Geek-Chow32 分钟前
Mobile App Certificate Pinning: Underlying Principle and a Swift Example
开发语言·ios·swift·安全架构
阿豪只会阿巴40 分钟前
两小时快速入门 FastAPI--第一回
开发语言·python·fastapi
Hesionberger1 小时前
动态规划与二分法破解最长递增子序列
java·数据结构·python·算法·leetcode
你怎么知道我是队长1 小时前
JavaScript 事件介绍
开发语言·前端·javascript
CodeStats1 小时前
【Linux IO】从文件描述符到硬件中断:Linux IO 系统底层完全拆解
java·linux·开发语言·io·socket