en_7123's Avatar, Join Date: Feb 2010
Ambitious contributor
Quote:
Originally Posted by virxen View Post
in which operation system?
I'm using linux fedora
en_7123's Avatar, Join Date: Feb 2010
Ambitious contributor
Quote:
Originally Posted by thapchi View Post
Well the main thing u r missing is

Scanf

its user input?

where will user enter?
If you put scanf it would wait for user input .Read the problem again.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Use getch() from the ncurses library.
en_7123's Avatar, Join Date: Feb 2010
Ambitious contributor
Quote:
Originally Posted by xpi0t0s View Post
Use getch() from the ncurses library.
I'm using C.Could you please explain or give me a link.Thanks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Try Google.
en_7123's Avatar, Join Date: Feb 2010
Ambitious contributor
Quote:
Originally Posted by xpi0t0s View Post
Try Google.
??? Ok thanks for that advice.Any one else who can help but not be so discreet would be appreciated.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Alright then, if you want it spoon-fed to you, how about:
Code:
int c=getch();
Then see what c contains when the user presses "e", for example by using printf, and if you need an example of that as well then it might be something like
Code:
printf("%d\n",c);
Then you can test for that specific value. And here's an example:
Code:
int c=getch();
if (c==CODE_FOR_E)
{
  printf("User pressed E\n");
}
(change CODE_FOR_E to the number returned by the previous bit).
en_7123's Avatar, Join Date: Feb 2010
Ambitious contributor
I have no intention of getting flamed now ..he he .And Thanks for putting together that code yeah but I'm doing it by using threads.
bluecoder's Avatar
Go4Expert Member
you will need the thread that will moniter the char to stop the printing . Create the new thread and use getchar( ) in that thread this will continue with the printing . till you press 'e' or 'E' .
virxen's Avatar, Join Date: Nov 2009
Pro contributor
this can be solved like this

Code:
#include<stdio.h>
#include<conio.h>
int main(){
    int i=0;
printf("enter key a to stop running");
char a='o';
while(a!='a'){
    while(!kbhit()){
        printf("\n%d",++i);
    }
    a=getch();
}

printf("\nyou pressed a and stopped the process!!!");
getchar();
}