c語言字串之拼接函式
阿新 • • 發佈:2021-02-12
strcat函式:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//關於字串的操作要包含標頭檔案sting.h
#include<string.h>
int main()
{
//strcat
char c1[32] = { 0 };
char c2[32] = { 0 };
strcat(c1, "hello");
printf("%s", c1);
strcat(c2, " world");
printf ("%s\n", c2);
strcat(c1, c2);
printf("%s", c1);
return 0;
}
strncat函式:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//關於字串的操作要包含標頭檔案sting.h
#include<string.h>
int main()
{
//strncat
char c1[32] ="hello";
char c2[32] =" world YES OR NO";
strncat (c1, c2,6);
printf("%s", c1);
strncat(c1, "\nGOODBYE THE WORLD!!!",8);
printf("\n%s", c1);
return 0;
}