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"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值