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;
}
相关推荐
你怎么知道我是队长4 分钟前
JavaScript的变量和数据类型介绍
开发语言·javascript·ecmascript
xingke16 分钟前
C 语言多文件编程:(一)头文件、extern、编译链接
c语言·开发语言·多文件
战族狼魂24 分钟前
GPT-5.6与Grok 4.5重磅发布
人工智能·算法·大模型·大语言模型
白日焰火11 小时前
基于 OpenSpec 实现规范驱动开发
算法·交互
戮漠summer1 小时前
Missing Semester 计算机教育中缺失的一课 Lecture 01 Shell
开发语言·后端·scala
jinyishu_1 小时前
C++ string使用方法
开发语言·c++
imuliuliang1 小时前
关于图搜索算法的性能建模与可预测性研究7
算法
EW Frontier1 小时前
三级跳突破864维动作空间——QMIX-Hierarchical多无人机协同通信方法全解析【附python代码】
开发语言·python·无人机·强化学习·通信资源分配
名字还没想好☜1 小时前
Next.js 中间件实战:鉴权、重定向与 A/B 分流
开发语言·前端·javascript·中间件·react·next.js
乐观勇敢坚强的老彭1 小时前
C++浮点数使用注意事项
开发语言·c++