Input control moves to next line automatically without using cout function

S

srini4vasan

#include <stdio.h>
int main()
{

char n, m;
puts (" Enter the first string and . to terminate :");
do
{
n = getchar();
putchar(n);
}while(n !='.');

puts (" Enter the second string and . to terminate :");
do
{
m = getchar();
putchar(m);
}while( m != '.');

return 0;
}

Output
------------
Enter the first string and . to terminate :
234.
234. Enter the second string and . to terminate :

2343.
2343.Press any key to continue

In the above program- output the i can't enter the value of the second
string in the same line.
Here control automatically moves to next line.

ie., The value cannot be entered in the same line even there is no
corresponding cout function.

thanks,
 
C

Chris Dollin

#include <stdio.h>
int main()
{

char n, m;
puts (" Enter the first string and . to terminate :");
do
{
n = getchar();
putchar(n);
}while(n !='.');

puts (" Enter the second string and . to terminate :");
do
{
m = getchar();
putchar(m);
}while( m != '.');

return 0;
}

Output
------------
Enter the first string and . to terminate :
234.
234. Enter the second string and . to terminate :

2343.
2343.Press any key to continue

In the above program- output the i can't enter the value of the second
string in the same line.

Yes, you can. You just didn't.
Here control automatically moves to next line.

ie., The value cannot be entered in the same line even there is no
corresponding cout function.

Yes, you can.

What you /can't/ do is get the prompt out in the middle.

To do what I think you want to do, you will have to step outside the
realm of standard C and use some implementation-defined extension.
IIRC, this is mentioned in the FQX (fx:hint). Once such extension
is [N]CURSES. You might find it easier to just drop the requirement.
 
A

Army1987

On Mon, 10 Sep 2007 06:35:45 -0700, srini4vasan wrote:

[snip]
In the above program- output the i can't enter the value of the second
string in the same line.
Here control automatically moves to next line.

Whatever you type will be sent to stdin only when you hit Enter,
so to allow you to edit lines with backspace without the program
knowing. See www.c-faq.com, question 19.1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top