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;
}
相关推荐
巧克力男孩dd7 分钟前
Python超典型练习题(第一次作业)
开发语言·python·算法
TlSfoward14 分钟前
TLSFOWARD TLS指纹
开发语言·数据库·爬虫·搜索引擎·https·php
爱刷碗的苏泓舒16 分钟前
平方根信息滤波:矩阵推导及 GNSS 参数估计应用
线性代数·算法·矩阵·gnss·参数估计·测量平差·平方根信息滤波
闲猫1 小时前
LangChain / Core components / Models
开发语言·python·langchain
想做小南娘,发现自己是女生喵1 小时前
第 2 章 顺序表和 vector
java·数据结构·算法
ComputerInBook2 小时前
c 和 c++ 中的宏块(macro)
c语言·c++··宏块·宏指令
艾醒2 小时前
2026年第29周(7.13-7.19)AI全复盘:技术突破、行业趣闻翻车、算力服务器商业动态
人工智能·算法
雪碧聊技术2 小时前
动态规划算法—01背包问题
算法·动态规划
-银雾鸢尾-2 小时前
C#中的索引器
开发语言·c#
bu_shuo2 小时前
c与cpp中的argc和argv
c语言·c++·算法