C - char字符串操作

char * 与 char[]的理解:

strncpy_s:char * 字符串复制
	#define MAX_FILE_SIZE 1024

	char copy_1[MAX_FILE_SIZE];
	char * c = new char[MAX_FILE_SIZE];
	c = "h = com.kk\nz = 1234567";

	strncpy_s(copy_1, _countof(copy_1), c, strlen(c));
	
	printf("%s\n",copy_1);
strcat_s:char * 字符串连接
	#define MAX_FILE_SIZE 1024
	char * str1 = "lll";
	char * str2 = "kkk";
	char * result = new char[MAX_FILE_SIZE];
	strcpy_s(result, 100, str1);//将str1的字符复制到result,result会被覆盖
	strcat_s(result, 100, str2);//将str2的字符复制连接到result之后,result不会被覆盖
	printf("%s\n",result);
strlen:计算char * 的字符长度
	#define MAX_FILE_SIZE 1024
	char * str1 = “lll”;
	int len = strlen(str1);
strstr(char * a,char * b):字符串比对,比对a中是否含有b,若有则返回a中,从b开始到结束的字符串
	#define MAX_FILE_SIZE 1024
	char * a= “asdfghjkl”;
	char * b= “fgh”;
	char * c = strstr(a,b);
        printf("%s\n", c);
        //最后打印为"fghjkl"

你可能感兴趣的:(C - char字符串操作)