/*
字符串处理函数:
>库函数:string.h
>函数原型:
char *strcpy( char *s1, const char *s2 );//copy字符串函数,返回s1的值,s2->s1;
char *strncpy( char *s1, const char *s2, size_t n );//s2->s1 至多复制n个字符
char *strcat( char *s1, const char *s2 );//connect字符串函数,返回s1的值,s1+s2;
char *strncat( char *s1, const char *s2 , size_t n );//s1 + s2中的至多n个字符.
//字符串比较函数:
int strcmp( const char *s1, const char *s2);
int strncmp( const char *s1, const char *s2, size_t n );
//字符串查找函数:
char *strchr( const char *s, int c );
char *strrchr( const char *s, int c );
char *strstr( char *s1, const char *s2 );
暂时不讲述:在"安全的C程序设计"中介绍
//字符串分解函数
char *strtok( char *s1, const char *s2 );
时间:Dec 29, 2017 13:28
*/
#include<stdio.h>
#include<string.h>
#define SIZE 100
int main()
{
const char *s1 = "woyoukexiaolidezhi";
const char *s2 = "is";
const char *s3 = "man";
char s4[SIZE];//创建字符串数组
puts( strcpy( s4 , s1 ) );//进行字符串复制函数并且输出函数返回的字符指针
puts( s4 );//输出s4,判断是否复制成功
memset( s4, 0, sizeof(s4) );//将复制的函数清零
strcat( s4, strcat( s4, s3));//进行字符串连接工作,在这里,s4原本为空,连接了"man"后与自己连接所以最后的s4为"manman";
puts(s4);//输出s4;
puts( strchr( s1, 'i') );//进行字符查找工作->首次找到返回指针
puts( strrchr( s1, 'i') );//进行字符查找工作->最后一次找到返回指针
puts( strstr( s1, "ao") );//进行字符串查找工作->首次找到返回指针
return 0;
}
/****************
woyoukexiaolidezhi
woyoukexiaolidezhi
manman
iaolidezhi
i
aolidezhi
请按任意键继续. . .
*/
字符串处理函数的用法案例
最新推荐文章于 2024-03-18 21:06:17 发布