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;
}
相关推荐
代码北人生2 分钟前
GitHub 日榜第一、月下载 110 万:supervision 出现之前,写计算机视觉代码是什么感觉
算法·claude
techdashen5 分钟前
Rust 社区在 4 月做了什么:项目管理月报解读
开发语言·rust·mfc
南宫萧幕6 分钟前
HEV能量管理策略 Simulink 实战:从零搭建 Rule-based 与 A-ECMS 对比模型及排错指南
人工智能·算法·matlab·simulink·控制
萧戈6 分钟前
C/C++ 运行时库概念详解
c语言·c++
十五年专注C++开发7 分钟前
QFluentKit: 一个基于 Qt Widgets 的 Fluent Design 风格 UI 组件库
开发语言·c++·qt·ui·qfluentkit
lly2024068 分钟前
PHP JSON 使用指南
开发语言
沐知全栈开发13 分钟前
jQuery 尺寸
开发语言
Byte Wizard15 分钟前
C语言指针深入浅出5
c语言·开发语言
csbysj202018 分钟前
Vue.js 监听属性
开发语言
匠在江湖18 分钟前
EtherCAT从站(LAN9252+STM32)配置全解析与优化指南
c语言