所以我剛剛開始學習編碼,但 VS 代碼表現得很奇怪?
當我在除錯模式下運行我的代碼時,代碼有時不起作用。當我要求“用戶輸入”與“不要求用戶輸入”時,代碼的反應不同。
代碼 - “不要求用戶輸入”
#include <stdio.h>
#include <stdlib.h>
int main(){
enum Company {
Google,
FaceBook,
XEROX,
YAHOO,
EBAY,
Microsoft
}COMPANY;
// int test;
// scanf("%i", test);
// printf("%i",test);
COMPANY = Google;
printf("%d\n", COMPANY);
int i;
for (i= Google; i <= Microsoft; i )
{
printf("%i\n", i);
};
return 0;
}
除錯控制臺的輸出 影像
代碼 - “用戶輸入”
#include <stdio.h>
#include <stdlib.h>
int main(){
enum Company {
Google,
FaceBook,
XEROX,
YAHOO,
EBAY,
Microsoft
}COMPANY;
int test;
scanf("%i", test);
printf("%i",test);
COMPANY = Google;
printf("%d\n", COMPANY);
int i;
for (i= Google; i <= Microsoft; i )
{
printf("%i\n", i);
};
return 0;
}
輸出:除錯控制臺的輸出
這是我的啟動 json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C : gcc.exe build active file"
}
]
}
uj5u.com熱心網友回復:
scanf("%i", test);
應該
scanf("%i", &test)
scanf()期望一個指向 int 的指標,但您傳遞的是一個int。
uj5u.com熱心網友回復:
除了呼叫中的語法錯誤 scanf()
當您輸入某個值時,您還必須輸入“回車”鍵,以便將數字通過終端傳遞給程式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/399826.html
上一篇:在vscode開發容器中,有沒有辦法從本地網路上的不同機器訪問docker容器?
下一篇:在結構中創建靈活的陣列大小
