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?

}

You can't. scanf() requires an ENTER.

And why is continue plural?

I think you can use getch(); function...

If getch() isn't available, see gcc equivalent for getch()

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

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.

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...

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

eg:

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

key=getch();

you may also use kbhit()

commented: READ THE THREAD!!!! -4

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.