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?

}

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 4 Years Ago by andy1973: clarification

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 4 Years Ago by WaltP: n/a

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 4 Years Ago by Ezzaral: removed promotion

Comments
READ THE THREAD!!!!

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 article has been dead for over six months. Start a new discussion instead.