[問題] 為何字串出現(NULL)

看板C_and_CPP作者 (Darren)時間10年前 (2015/12/10 12:33), 10年前編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/1
開發平台(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
_s 不是應該要三個參數嗎
12/10 12:39, 1F

12/10 12:39, , 2F
回傳值也不是 ptr
12/10 12:39, 2F

12/10 12:45, , 3F
也可以是兩個參數,另外他們是回傳errno_t
12/10 12:45, 3F
我以為strcpy跟strcpy_s用法一樣.. 那我應該怎麼改呢?

12/10 12:50, , 4F
先做_s,再用printf把pstr2和str3印出來就好
12/10 12:50, 4F
哦哦~是我誤會用法了~~ 萬分感謝!! ※ 編輯: darrenliuptt (36.231.119.37), 12/10/2015 12:52:59
文章代碼(AID): #1MQG2nZT (C_and_CPP)