字符串处理函数

来源:互联网 发布:软件行业的发展趋势 编辑:程序博客网 时间:2024/06/06 07:09

字符串处理
1,求字符串长度
size_t strlen(char const *string);
size_t:无符号整数类型

char buffer[]="hello world";printf("%d\n",strlen(buffer));

2,复制字符串
char * strcpy(char * dst,char const *src);
这个函数把参数src字符串复制到dst字符串
必须保证:目标字符数组的空间足以容纳需要复制的字符串。

#include<stdio.h>#include<string.h>int main(){    char message[100]="hello world";    strcpy(message,"yang kai");    printf("%s",message);    return 0;}

3,连接字符串
char * strcat(char * dst,char const *src;
src中的字符,被放到了dst最后的字符的

char message[100]="hello world";strcat(message," yang kai");/*函数strcpy(),和函数strcat()的函数返回值都是char* 是第一个参数的一份拷贝,就是一个指向目标字符数组的指针*/

4,字符串比较函数
int strcmp(char const *s1,char const *s2);

原创粉丝点击