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
Related
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.
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).
I have tried running a simple piece of C code in DevC++.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
printf("Temporary secretary");
return 0;
}
Every time i try to compile it, it makes "makefile.win" and points out an error on line 25.
screenshot
The error message in the build window is telling you exactly what the problem is - you have multiple definitions of main, one in main.c and the other in Untitled2.c.
Based on what you have posted, it's not clear why Untitled2.c is part of the build - I would remove it from the project completely.
In the future, please do not post links to images of screenshots - copy and paste any code (which includes makefiles) and error messages into the body of your question. We can't copy and paste from a screenshot, and chasing random links is unsafe.
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;
}
This message appears when i run my program through Code::Blocks
And Here is my code.I am not trying to create something huge , for now i want to figure out what pdcurses functions do.
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <string.h>
int main()
{
int maxx=80, maxy=54;
initscr();
getmaxyx(stdscr, maxy, maxx);
printw("maxy= %d maxx= %d \n", maxy , maxx);
refresh();
getch();
endwin();
return 0;
}
I'm pretty sure it's failing on initscr(), rather tham getmaxyx(). This looks like another variation of the problem you posted here, where the IDE is giving you only a partial console environment to run in, as part of its attempt to keep things integrated. I'm not a user of either Code::Blocks or Eclipse, so maybe I'm off-base here, but that's what it looks like to me.
So again, try manually opening a cmd window from the OS, and running the program from there. (Or, starting the program from Windows Explorer should automatically create a console window.)