Reputation: 11
I am writing a game code in C which involves display of numbers with a time gap entered by the user.
srand ( time(NULL) ); //this avoids generating the same random number everytime
start:
mySleep(userdelay);
printf("\n\n\a\t%d",rand()%90); //prints random numbers with the time delay entered by the user.
goto start;
So I just wanted to know how to pause this loop with user input like "Press 1 to pause" and resume the same loop with user input like "Press 2 to resume".
Thanx in advance!
Upvotes: 0
Views: 5560
Reputation: 2181
I'm not sure this may be the best way, but it could be one working way. Try using a while loop in your command console:
int main(){
int i;
scanf("%d",&i)
switch(i){
case 1: while(i != 2){
sleep(1); //or define duration by a variable if time should be "dynamic"
scanf("%d",&i);
break;
}
}
}
I hope you get an idea of the idea.
EDIT:
If you want the user to input data until "exit key" a while loop is much bether than goto. If you are not familiar with switch(){}
i advice you to take a look here.
Upvotes: 2