Help with simple program

Ambitious contributor
9Mar2010,14:34   #1
en_7123's Avatar
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
haru31773's Avatar
so it should continue printing until the user presses E?
Light Poster
9Mar2010,16:52   #3
rekha_sri's Avatar
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
en_7123's Avatar
Quote:
Originally Posted by haru31773 View Post
so it should continue printing until the user presses E?
Yes
Pro contributor
10Mar2010,13:18   #5
virxen's Avatar
Quote:
Originally Posted by rekha_sri View Post
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;
}
}


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
lipun4u's Avatar
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
en_7123's Avatar
Quote:
Originally Posted by rekha_sri View Post
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;
}
}
Well this doesn't exactly help because the program does not continue printing numbers and it waits for a user input after each number is printed.
Ambitious contributor
10Mar2010,16:07   #8
en_7123's Avatar
Yup exactly guys could any one help me with this.How to go about it.
Pro contributor
10Mar2010,16:11   #9
virxen's Avatar
in which operation system?
Go4Expert Member
10Mar2010,16:22   #10
thapchi's Avatar
Well the main thing u r missing is

Scanf

its user input?

where will user enter?