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.
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; }
Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.
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.
My best code is written with the delete key.
Thanks. Who woulda thunk to put in 2 getchar()s. Maybe everyone else but me.