Hi
I've just picked up a copy of SAMS teach yourself C in 21 days (I dont think Ill finish it that quickly) because I wanted to get into programming. I've worked through the first chapter, but keep enountering a problem: my programs exit before I can see what they are. The first program (Hello world!) compiles fine, but just flickers up then quits.
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
return 0;
}
The same happenes with other programs in the chapter. I found in a forum that replacing
return 0;
with
fflush(stdout);
(void)getchar();
to look like
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
fflush(stdout);
(void)getchar();
}
fixes this - which it did, but still exits when I press enter; which is not ideal for programs which require it. I assume there is something obvious which i am missing, but for the life of me cant see what. I have tried searching for answers but havn't turned up and clues, not that I even know what to search for.
Any help would be appreciated.
PC