【发布时间】:2021-12-29 09:55:28
【问题描述】:
所以我刚开始学习编码,但 VS 代码表现得很奇怪?
当我在调试模式下运行我的代码时,代码有时不起作用。 当我要求时,代码的反应不同 “用户输入”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;
}
CODE - “用户输入”
#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"
}
]
}
【问题讨论】:
-
scanf("%i", test);==>scanf("%i", &test);启用编译器警告!另外不要使用%i,除非您希望允许用户以其他数字为基础输入数据。如果他们输入012,那是十进制的八进制,而不是十二。最好使用%d。 -
作为这里的新用户,也请收下tour并阅读How to Ask。此外,决定使用一种(!)编程语言,也请参阅您应用的标签的描述。此外,当您遇到代码问题时,请先提取minimal reproducible example!
-
另外,请不要对代码进行“进度”更新。
标签: c visual-studio-code vscode-debugger