[問題] 關於字元和字串顯示錯誤問題(已解決)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Visual Studio 2013
win7 64bit
問題(Question):
為兩題洪維恩的C語言教學手冊範例 prog4_13和prog4_15
餵入的資料(Input):
Q1:輸入R字元
Q2:輸入字串Alice
預期的正確結果(Expected Output):
Q1:ch=R, ASCII code is 82
Q2:Hi, Alice, How are you?
錯誤結果(Wrong Output):
Q1:出現無法正確啟動(0xc0000142),錯誤視窗如下
http://ppt.cc/q4KU
Q2:字串Alice無法顯示出來,錯誤視窗如下
http://ppt.cc/WnE4
程式碼(Code):(請善用置底文網頁, 記得排版)
Q1:/* prog4_13, 輸入字元 */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char ch;
printf("Input a character:");
scanf_s("%c",&ch); /* 由鍵盤輸入字元並指定給變數ch */
printf("ch=%c, ascii code is %d\n",ch,ch);
system("pause");
return 0;
}
Q2:/* prog4_15, 輸入字串 */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char name[10]; /* 宣告字元陣列 */
printf("What's your name: ");
scanf_s("%s",name); /* 輸入字串,並由字元陣列name所接收 */
printf("Hi, %s, How are you?\n",name); /* 印出字串的內容 */
system("pause");
return 0;
}
補充說明(Supplement):
完全依書上範例無更動程式碼
已google過,但都無法解決問題
懇請各位幫忙.
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.179.16
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1398934430.A.8DF.html
→
05/01 16:56, , 1F
05/01 16:56, 1F
→
05/01 17:03, , 2F
05/01 17:03, 2F
→
05/01 17:03, , 3F
05/01 17:03, 3F
推
05/01 19:32, , 4F
05/01 19:32, 4F
→
05/01 20:19, , 5F
05/01 20:19, 5F
推
05/03 01:47, , 6F
05/03 01:47, 6F
※ 編輯: bat205 (114.45.94.105), 05/04/2014 16:18:30
→
05/04 16:20, , 7F
05/04 16:20, 7F
→
05/04 16:21, , 8F
05/04 16:21, 8F