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;
}
相关推荐
新时代牛马8 分钟前
字符设备驱动完整篇:从 cdev_add、file_operations 到chrdev_open 与排障
开发语言·python
swordbob11 分钟前
ReentrantLock 与 AQS 完整学习手册
java·开发语言
政企项目老覃44 分钟前
大模型幻觉治理与自动评测:金融风控场景的落地实践
人工智能·算法·机器学习
是隼人1 小时前
buuctf-pwn inndy_echo(32位fmt)题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
淡海水1 小时前
08-03-不可变-ImmutableDictionary-TKey-TValue-与ImmutableHashSet-T-持久化哈希树
数据结构·算法·c#·哈希算法·dictionary·immutable
白山编程大哥1 小时前
Java OutputStreamWriter 详解:从字符到字节的桥梁
java·开发语言·python
hansang_IR1 小时前
【题解】[APIO2023] 赛博乐园 / cyberland
c++·算法·图论
洛阳纸贵2 小时前
MATLAB-matlab基础知识
学习·算法·matlab
落羽的落羽2 小时前
【AI】快速理解AI应用的相关名词概念
linux·c++·人工智能·python·计算机网络·算法