OK I'm trying to have a simple loop which keeps on printing each number from 1,2,... on a different line and it keeps on doing so until the user enters 'e'.
e.g
for(i=0;i<=9999999999;i++)
{
printf("%d\n",i);
}
It does not take any input from user and keeps on printing but as soon as user presses e the program exits.Any clue how to go about this.
|
Light Poster
|
|
| 9Mar2010,16:10 | #2 |
|
so it should continue printing until the user presses E?
|
|
Light Poster
|
|
| 9Mar2010,16:52 | #3 |
|
Use the following program for printing the integer value unless press E or e. This example will help for your requirement.
Code:
#include<stdio.h>
#include<stdlib.h>
main()
{
long i;
char c;
for(i=0;i<=99999;i++)
{
printf("%d",i);
c=getchar();
if(c == 'e' || c == 'E')
{
break;
}
continue;
}
}
|
|
Ambitious contributor
|
|
| 10Mar2010,10:02 | #4 |
|
Pro contributor
|
![]() |
| 10Mar2010,13:18 | #5 |
|
Quote:
Originally Posted by rekha_sri with getchar you stop the execution of the program until the user press enter. certainly not what he wants. And no this is not a simple program. There is not an easy way to do it(especially platform independent). |
|
Light Poster
|
|
| 10Mar2010,13:56 | #6 |
|
You need thread or process creation and some signal stuff.
Create a child process which will print the numbers and the parent process will take user input. |
|
Ambitious contributor
|
|
| 10Mar2010,16:00 | #7 |
|
Quote:
Originally Posted by rekha_sri |
|
Ambitious contributor
|
|
| 10Mar2010,16:07 | #8 |
|
Yup exactly guys could any one help me with this.How to go about it.
|
|
Pro contributor
|
![]() |
| 10Mar2010,16:11 | #9 |
|
in which operation system?
|
|
Go4Expert Member
|
|
| 10Mar2010,16:22 | #10 |
|
Well the main thing u r missing is
Scanf its user input? where will user enter? |


