strcat 和 strncat
strcat与strncat都是字符串连接函数,功能上稍有区别:
strcat可以把一个字符串的全部内容复制到另一个字符串的后面;
strncat则是把一个字符串的指定长度复制到另一个字符串的后面,如果指定长度超出字符串的长度,则会复制整个字符串。两个函数的语法结构分别如下:
Action() { char str1[] = "This is"; char str2[] = "a "; char str3[] = "strcat&strncat"; char str4[] = "test!"; lr_output_message("%s",str1); strcat(str1,str2); lr_output_message("%s",str1); strncat(str1,str3,100); lr_output_message("%s",str1); return 0; } 输出: This is This isa This isa strcat&strncat