0

I want my program to just continue as long as the user press any key
How do we do it with only use of scanf??

for example:


int main(void)

{

while(1)
/*my program goes here*/

printf("Hit any keys to continues......");
scanf // how?

}

5
Contributors
8
Replies
10
Views
5 Years
Discussion Span
Last Post by andy1973
0

And what if you aren't using a gcc compiler?

If one's compiler includes the header file conio.h, getch() is most likely defined there. If his or her compiler doesn't include conio.h, the link I posted above may work.

Edited by andy1973: clarification

0

You aren't listening. Try to learn something...
Look up conio.h in the C Standard...
Look up the information in your link in the C Standard...

Edited by WaltP: n/a

-1

use getch() function for this...no need to use scanf()

eg:

printf("press any ket to continue..");

key=getch();

you may also use kbhit()

Edited by Ezzaral: removed promotion

Votes + Comments
READ THE THREAD!!!!
0

getch() with the conio.h provided with some compilers is non ANSI compliant, however, if you use the user defined method outlined at http://zobayer.blogspot.com/2010/12/getch-getche-in-gccg.html
you would get ANSI/ISO compliant code. The output from my compiler when I tell it to enforce strict ANSI

andy@debian:~/prog/c$ gcc -Wall -pedantic -ansi conio.h -o conio
andy@debian:~/prog/c$

No errors or warnings are displayed when I compile the header.

3.3.2 Strict ANSI/ISO

The command-line option -pedantic in combination with -ansi will cause gcc to reject all GNU C extensions, not just those that are incompatible with the ANSI/ISO standard. This helps you to write portable programs which follow the ANSI/ISO standard.

http://www.network-theory.co.uk/docs/gccintro/gccintro_28.html

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.