Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple hello world runs but printf does not print to command line

Tags:

c

#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}

This is my simple hello world program given to me by my professor. I was given this to copy as my first program in C. I am using visual studio 2013 as instructed and I am on a Surface Book running windows 10. A classmate that is on the exact same setup runs this program just fine. Mine will build and when I run without debugging the console window opens and no text prints. I cannot find a solution online.

like image 947
jon kaban Avatar asked Dec 06 '25 03:12

jon kaban


1 Answers

Make sure your program doesn't just finish and close the console so quickly that you cannot see anything. Try this:

#include <stdio.h>

int main()
{
    printf("Hello World\n");
    fflush (stdout); /* Make sure string is outputted to std output */
    getchar(); /* waits for a key to finish */
    return 0;
}
like image 116
mcleod_ideafix Avatar answered Dec 07 '25 19:12

mcleod_ideafix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!