This is a total noob question but when I run a simple program how do I keep my program window open until I enter a character from the keyboard. Like I said, I'm new at this and thought I might come here for help. Thanks in advance.
Printable View
This is a total noob question but when I run a simple program how do I keep my program window open until I enter a character from the keyboard. Like I said, I'm new at this and thought I might come here for help. Thanks in advance.
Nevermind. I'm kind of slow at this, but I figured it out. Thanks.
for example
Code:#include<stdio.h>
#include<conio.h>
int main()
{
printf("input a char to exit the program\n");
getch();
return 0;
}
Thanks for the response.
Well I thought I fixed it.
I've tried the
but it doesn't keep the DOS window open so that I can view the input numbers.Code:#include <stdio.h>
main()
{
char d1, d2, d3, d4;
int x;
scanf("%d%c%c%c%c", &x, &d1, &d2, &d3, &d4);
printf("%d%c%c%c%c", x, d1, d3, d2, d4);
getchar();
return 0;
}
scanf left a newline in the stream and getchar read it. Throw in another getchar to eat the newline and you'll be set.
Thanks. :confused: Who woulda thunk to put in 2 getchar()s. Maybe everyone else but me. :)