Why does this show after running my C program? - c

So, after running this code in Visual Code:
#include <stdio.h>
int main(){
printf("Hello!");
return 0;
}
I get this in my console:
image
What's up with all that added text?

Because you're running your program under Visual Studio Code's debugger, and for some reason it prints out a bit of job control trash on the console.
Maybe add a newline at the end of your print, to make your output clearer:
printf("Hello!\n");
Alternatively, don't run under the debugger (look for a "Run without debug" option).

Related

How to create a C console application in Visual Studio Code

I haven't found any extension, or tutorial to make and execute a C console application in the VSCode Terminal.
A simple program like
int main()
{
printf("Hello World!");
return 0;
}
And have the output in the VSCode Terminal.
Does someone know how to realize this? And/or are there solutions?
Thanks in advance
Regards
There actually is an extension for c/c++ on VSCode:
When you click the arrow in the top right (to run the file) you will be asked which compiler you want to use. In our case we can use the gcc compiler:
Then you can paste your code into a .c file and run it with the compiler. It should automatically also execute the binary and print your output into the debug-console:
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
Hello World!
You even have a debugger, if you set certain breakpoints!
Extra:
Make sure that you have the correct OS set in the bottom right (in the status bar), so your c code compiles for your machine specifically.

VS Code using C not outputing to "Output" Tab

I've been tring to program on VS Code in C for quite a while now but i can't get the output to go in the correct spot
As you can see in this really short test code:
#include <stdio.h>
int main()
{
printf("This is a test \n");
}
,and the adjacent image, the output goes to the debug console and not the output tab, or even the terminal
Does anyone have any clue as to why this is happening?
https://i.stack.imgur.com/iujLs.png

How to compile C program in Visual Studio Code?

I installed VSC and wrote this program
#include <stdio.h>
int main( void )
{
printf("Hello world!");
}
Then I installed a C/C++ debugger and I saved the file on the desktop as "hello.c" and magically the syntax became higlighted.
Now I would like to run the program, but can't find a way.
There's no "run" or "build" option anywhere, and if I start the debugging and choose the debugger then I got a new tab named "settings.json" with a couple of brackets waiting for me to write something.
Also in the left I can read that I "have not yet opened a folder". What does it even mean?
And the line #include <stdio.h> is underlined in red, like there's something wrong going on, maybe I have to download the library?
I would do anything to see the output of the program, please help me.
have you added c/c++ and code runner extensions?

Why Ecplise (CDT) console and debug don't work properly?

I have the following problem with a C code in Eclipse. This is the minimal code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char inputch[20];
fgets(inputch,20,stdin);
printf("%s", inputch);
getchar();
return EXIT_SUCCESS;
}
The code is built correctly and if I run it from the built .exe, it works properly: I write a line and press ENTER, then the line entered is showed in the console and then if I press any button in the keyboard the console shutdown.
But the behaviour is different if I run the program in the "run mode of eclipse": when I write the line and I type ENTER, nothing happen; when I type ENTER once again, the line I wrote before appears in the console and the program ends. If I wrote something between the first and the second ENTER, this line doesn't appear in the stamp; however, the stamp appear always at the second ENTER typing, the same that ends the programs, like the getchar and the printf are inverted.
The second problem is in debug mode: if I try to debug the code, if I put a breakpoint in the fgets() function and try to step into, the debug console doesn't permit me to write the entry in the STDIO, but step immediatly at the next statement.
MY CONFIGURATION: eclipse Neon 3 4.6.3 x64, CDT, Cygwin compipler x64, windows 8.1 64 bit
EDIT: I tried also with miniGW but the problem persist. The debugger, in both case, is GDB 7.6.11

Error running *.c file in Eclipse Kepler

I've started programming in C so weeks ago, and I choose Eclipse Kepler as my IDE for C, since I had already used it for programming in some other languages and really liked.
However, after I had installed Cygwin and the C programming tools in Eclipse, I tried to run the old "Hello World" and it didn't work, It didn't appeared anything in the Console, only the message "Terminated".
#include <stdio.h>
int main(){
printf("Hello World!");
return 0;
}
Anyone has any idea what the problem could be?
Thanks to all of you. I tried everything you said but I wasn't able to get my problem solved. I gave up! Right now, i'm using as workspace in eclipse the Cygwin home. I write the program in the Eclipse and run it in the Cygwin command line.
Again, thanks to all for trying to help, it won't be forgotten. You're a really awesome crowd!
Maybe the program was too fast for you to see it?
The window with the program output appeared and disappeared in the blink of an eye.
You could try to prevent that from happening by changing your program to do its stuff AND wait for ENTER before it terminates.
#include <stdio.h>
int main(){
printf("Hello World!");
getchar(); /* simple wait for ENTER, error prone in more complicated programs */
return 0;
}
Note: your original program "prints a string"; this version "prints a string and waits for ENTER". It's a program with different requirements. If you want to keep to your initial requirements, try running the program from the DOS console.
you could try to system("pause") may this can help
#include <stdio.h>
int main(){
printf("Hello World!");
system("pause");
return 0;
}

Resources