[問題] 為何字串出現(NULL)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VS2012
C++
問題(Question):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[]="Apple iphone 4";
char pstr1[]="iPod";
char pstr2[20]="Apple";
char str3[20];
printf("str字串的長度是%d\n", strlen(str));
printf("pstr2連結pstr1後的字串為:%s\n", strcat_s(pstr2, pstr1));
printf("str3字串如下:%s\n", strcpy_s(str3, pstr1));
system("PAUSE");
return 0;
}
補充說明(Supplement):
執行結果: http://tinyurl.com/zfgpz9x
為何字串都變成(NULL)??
感謝幫忙~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.119.37
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1449722033.A.8DD.html
推
12/10 12:39, , 1F
12/10 12:39, 1F
→
12/10 12:39, , 2F
12/10 12:39, 2F
→
12/10 12:45, , 3F
12/10 12:45, 3F
我以為strcpy跟strcpy_s用法一樣..
那我應該怎麼改呢?
→
12/10 12:50, , 4F
12/10 12:50, 4F
哦哦~是我誤會用法了~~
萬分感謝!!
※ 編輯: darrenliuptt (36.231.119.37), 12/10/2015 12:52:59