開發平台(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過,但都無法解決問題
懇請各位幫忙.