473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Input control moves to next line automatically without using cout function

#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,

Sep 10 '07 #1
2 1989
sr*********@gmail.com wrote:
#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.

--
Chris "oops! concrete floor." Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Sep 10 '07 #2
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.
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen

Sep 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Jason Heyes | last post by:
I want to allow objects of my class to be read from an input stream. I am having trouble with the implementation. Here are the different approaches I have tried: // Version 1.0 - Default...
2
by: Lyn | last post by:
Hi, I have a text control on a form which is bound to table field StartDate which is in Date format. When updating the table record via the form, any data entered into the StartDate control is...
5
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
9
by: sherifffruitfly | last post by:
Hi, I've a got a little (exercise) program that reads data from a file and puts it into struct members. I run into trouble when one of the data pieces is comprised of several words (eg "john...
3
by: Prof.Stanley | last post by:
Hello all, please i am trying to write a program that recieves a string from user and counts double vowels.I have a problem particularly in the way to input the string,below is my code please will...
20
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want...
5
by: Kavya | last post by:
I saw these two ways for validating input First Way -------------- #include <iostream> #include <limits> using namespace std; int main() {
8
by: yomama | last post by:
Hello, I am writing a program in which I take a string (specifically, first and last name with a space in between) from the user and put it into a data member of a class node. I have tried various...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.