So I just Started Learning to code but VS code is acting weird ?
When i run my code in Debug mode the code sometimes does not work.
The code react differently when i ask for
"user input" VS "NOT asking for User Input".
CODE – "NOT asking for User Input"
#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("%dn", COMPANY);
int i;
for (i= Google; i <= Microsoft; i++)
{
printf("%in", i);
};
return 0;
}
Output
Image of the Debug Console
CODE – "user input"
#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("%dn", COMPANY);
int i;
for (i= Google; i <= Microsoft; i++)
{
printf("%in", i);
};
return 0;
}
Output: Output for debug console
Here is my launch 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"
}
]
}
2
Answers
should be
scanf()
expect a pointer to int, but you’re passing anint
instead.besides the syntax error in the call to
scanf()
when you enter some value, you have to also enter a ‘enter’ key so the number is passed through the terminal to the program.