字符串函数介绍

strcpy(字符串拷贝)

#include <stdio.h>
#include<string.h>
int main(){
	char string[10];
	char *str="fsdfsdg";
	strcpy(string,str);//将参数str字符串拷贝至参数dest所指的地址
	printf("%s\n",string);
}

strcat(字符串拼接)

#include <stdio.h>
#include<string.h>
int main(){
	char destination[25];
	char *blank=" ",*c="C++",*Borland1="Borland";
	strcpy(destination,Borland1);
	strcat(destination,blank);
	strcat(destination,c);
	printf("%s\n",destination);

}

strcmp(字符串比较)

#include <stdio.h>
#include<string.h>
int main(){
	char *a="asdfghjk";
	char *b="ASDFGHJK";
	char *c="azsdfghj";
	char *d="asdfghjk";
	printf("%d\n",strcmp(a,b));//根据ASCII码比较,若参数相同返回0,大于返回1,小于返回-1
	printf("%d\n",strcmp(a,c));
	printf("%d\n",strcmp(a,d));
}

strlen(计算指定字符串的长度,不包括结束字符‘\0’)

猜你喜欢

转载自blog.csdn.net/qq_38900441/article/details/105253705