This would be better
printf("Hit 'ENTER' to exit\n");
fflush(stdout);
(void)getchar();
I'd like to know more about why this is better. I understand the fflush to force the buffered printf output to the screen immediately. But why the cast to void for getchar's return value? Does this prevent allocation of bytes for the int ?
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
lint is outdated, compilers have now good enough error checking, so that we don't need lint.
Apparently you must be speaking from ignorance of the capabilities of a modern linter.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
system("pause")
It works but it is platform dependant and incurrs a lot more overhead than getchar(). Most C/C++ developers of any ilk will tell you not to use system("pause").
If you search on this site or using Google you can find plenty of lengthy explanations why it's not a good practice.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
I found out what the deal was.... instead of creating a new source file, i created a new project. When creating a new file, my tool writes this in the file as part of the template:
system("pause");
Edit the template to get rid of that awful command. I did... :icon_wink:
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944