BeenJammin2014
BeenJammin2014

Reputation: 31

Where should I be looking for the output in visual studio?

So I am not a programmer but I've decide to learn C and have found a website with great material (https://www.learn-c.org/). As a student I was able to get Visual Studio Enterprise 2017 for free. So as you may understand I'm not well versed in either C, programming, or VS2017. For lesson 1 on this site I must create my own Hello_World program. In VS2017 I opened an empty project and then opened a new file (Test.c). I believe my code is correct, however when I try to run it (Shift + F5) I do not see the "Hello World". A command prompt flickers on my screen for a bit. In a panel labeled "Output" on the bottom of VS 2017 I get this:

1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>Test.c
1>Project1.vcxproj -> C:\Users\Fabien\source\repos\Project1\Debug\Project1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

So my question is where should I be seeing "Hello, World!" ?

#include <stdio.h>
int main(){
printf("Hello World");
return 0;
}

Upvotes: 3

Views: 89

Answers (2)

paxdiablo
paxdiablo

Reputation: 882366

Shift-F5, unless you've reconfigured the default keys, is to stop debugging, so I'm not sure why you think that would help :-)

Pressing F5 on it's own will run your code, but in a mode that means it will simply exit once done, and the output window will disappear. If you need to do it that way, you can simply put a getchar() before exiting.

However, I'm not a big fan of having to change code just for debugging and, in any case, exiting may occur somewhere other than the end of main().

So I find it preferable to simply use Ctrl-F5 to run it in such a way that the IDE itself will leave the window open until you press a key:

<Your program output goes here>
Press any key to continue . . .

Upvotes: 1

mdatsev
mdatsev

Reputation: 3879

You program is working correctly but it is executed in a separate window and it is closed immediately after it finishes so you don't get a chance to see the output. You can use a function that halts the program and waits for input, for example getchar like so:

#include <stdio.h>
int main() {
    printf("Hello World");
    getchar();
    return 0;
}

this way the program will wait for input and then close.

Upvotes: 2

Related Questions