字符串函數
#include <stdio.h>
#include <string.h>
int main()
{
? ? char s1[100]="";
? ? char s2[]="我愛,";
? ? char s3[]="慕課網";
? ? /*在以下補全代碼*/
? ? strcat(s1,s2);
? ? strcat(s1,s3);
? ? printf("%s\n",s1);
? ? return 0;? ??
}
都是strcat()可以嗎?輸出是正確的,運行是錯誤的,
#include <stdio.h>
#include <string.h>
int main()
{
? ? char s1[100]="";
? ? char s2[]="我愛,";
? ? char s3[]="慕課網";
? ? /*在以下補全代碼*/
? ? strcat(s1,s2);
? ? strcat(s1,s3);
? ? printf("%s\n",s1);
? ? return 0;? ??
}
都是strcat()可以嗎?輸出是正確的,運行是錯誤的,
2018-03-25
舉報
2018-03-25
strcat在使用時s1與s2指的內存空間不能重疊,且s1要有足夠的空間來容納要復制的字符串