473,385 Members | 1,673 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,385 software developers and data experts.

C-programming

I Have tiped program as given below

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int age;
  5.     char sex,ms;                        
  6.     printf("enter age=");
  7.     scanf("%d",&age);
  8.     printf("enter sex=");
  9.     scanf("%c",&sex);
  10.     printf("enter marital status=");
  11.     scanf("%c",&ms);
  12.     getch();
  13.     return 0;
  14. }

Sir,
I am Kanchan Undre,from Belgaum(karnataka state),I have typed the above program in
visual studio 2008 express edition and also in Turbo c,when i execute the said program
the first printf() fuction outputs the message "enter age=" and after supplying the value to
it the second and third printf() functions output the message together as
"enter sex=enter marital status="instead of second printf() function ("enter sex=").
why does the second printf() combines with the third printf() output the message together?
Aug 8 '11 #1
1 1706
weaknessforcats
9,208 Expert Mod 8TB
When you enter the age the number goes into your variable but te \n (enter key) does not. That's becuase scanf stops when it sees a character that can't be part of your variable. It stops and leaves that character in the input stream.

Then the ext scanf sees the \n and it stops adn so on.

You will need to fetch the \n before you so the next scanf. Usually a getc into a scratch variable is used.
Aug 8 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Mike Tyndall | last post by:
Sorry I'm late, everybody! I'll try to post it nearer the start of the month next time. Updates: -Books added: C++ Coding Standards (Required Reading - upcoming) Memory as a Programming...
0
by: Mike Tyndall | last post by:
Whoops, way late this time. Sorry again, things have been hectic. Updates: -Books added to the "Other C++ books" section: Inside the C++ Object Model -Books added to the "General programming"...
10
by: just4me | last post by:
Exactly how do I read a specific location in the bios eprom. (such as debug.exe location ffff:0000)
12
by: Mars | last post by:
I searched and found quite many, but (nearly) all are about C++....... Any recommendation for such reference for pure C???? Thx~~~~ Mars.
14
by: chitu | last post by:
Hi pals, Hope u all of r intersted in C programming.Let start from d basics.
7
by: ledzepfan32 | last post by:
Hello, I just purchased Sam's Teach Yourself C++ in 21 days book for my independent study, and was wondernig if anyone had examples of beginner programs that could be made after such a book was...
2
RedSon
by: RedSon | last post by:
Here's a list of beginning stuff: Wikipedia http://en.wikipedia.org/wiki/C_%28programming_language%29 http://en.wikipedia.org/wiki/C%2B%2B
2
by: lnatz | last post by:
Is there a command in C that can copy only a segment of a string? For example, if I have a string "~/CProgramming/gaming" and I want to strcat the segment "/CProgramming/gaming" to "/home/natalie"...
1
by: manish2008 | last post by:
Assignment statement Background theory Consider a phasor at an angle of Ø (0 <= Ø <= 90°) with projections on the x and y axes as x0 and y0, respectively. Let it be rotated by an angle of Ø0...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.