C++分别编写实现下列字符串处理的函数,用指针作为参数

[复制链接]
查看11 | 回复1 | 2010-5-18 22:39:01 | 显示全部楼层 |阅读模式
1) char* trim(char *s)
删除字符串 s 的尾部空格
2) char* leftstring(char *s1, char *s2, int n)
得到指定字符串 s1 中前 n 个字符的子串 s2
3) int index(char *s1, char *s2)
检查字符串s2是否为字符串s1的子串,根据查找结果返回s2在s1中的开始位置,不成功返回 -1

回复

使用道具 举报

千问 | 2010-5-18 22:39:01 | 显示全部楼层
#include#includeusing namespace std;char* trim(char *s);char* leftstring(char *s1, char *s2, int n);int index(char *s1, char *s2);int main(){ char str1[]="I'm student. ",str2[]="student",str3[4]; int n; cout<<"串str1:"<<str1<<"长度为:"<<strlen(str1)<<endl; trim(str1); cout<<"串str1:"<<st
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行