Pages

Thursday, July 14, 2011

The scanf() Function in C and C++

Function name:  scanf()
Function Header: <stdio.h>
Declaration: int scanf (const char *format [, address,………..]);
Return Value:  On success, the scanf() function return the number of input fields successfully scanned, converted and stored.  Return 0, if no fields were stored

The scanf() function scans and formats input from stdin. It scans a series of input fields (all the characters up to the next white-space character) at a time. The format of scanf() function is scanf (“Formatted_specifier”, &variable_name). If you don’t use the & (Ampersand or Address Operator), you might get undesired result. So you should be careful to put it before the variable name. 


The list of formatted specifiers


Formatted Specifier
Meaning
%d
For storing integer value
%c
For storing a character
%s
For storing string
%f
For storing float and double value










Example of the scanf() function

#include<stdio.h>
#include<conio.h>

void main()
{
   int i;
   char c;
   char s[10];
   float f;

   clrscr();
   printf("Enter an integer number:");
   scanf("%d",&i);
   fflush(stdin);
   printf("Enter string:");
   scanf("%s",s);
   fflush(stdin);
   printf("Enter a floating number:");
   scanf("%f",&f);
   fflush(stdin);
  printf("Enter a character:");
  scanf("%c",&c);

   printf("\nYou have entered \n\n");
   printf("integer:%d \ncharacter:%c \nstring:%s \nfloat:%f",i,c,s,f);
   getch();
}

Here four formatted inputs are stored with scanf() function. There is no need to declare the address Operator (&) for storing string value because variable name is the original address for string value. The fflush(stdin) function is also being used to flush the buffer.
If you don't use fflush(stdin), there will be a problem in buffer and you can’t store inputs properly by scanf() function.

Output

25 comments:

Anonymous said...

My family members always say that I am wasting my time here at web,
but I know I am getting experience every day by reading thes fastidious articles.
Also visit my web page : transfer news football chelsea

Anonymous said...

An interesting discussion is definitely worth comment.
I do believe that you should write more about this subject matter, it may not be a taboo subject but typically people do not
talk about these topics. To the next! Best wishes!!

Also visit my web site :: Buy Bungalow

Anonymous said...

Hi, constantly i used to check webpage posts here in the early hours in the break of day, because
i love to learn more and more.

Feel free to visit my web site visit this site

Anonymous said...

The theme of the album I am Sasha Fierce revolves around the
duality between the godly Beyonce and the evil Sasha Fierce.
We feel devastatingly empty about how we must" separate the art from the artist Philip Larkin was a compulsive fake vagina then. I reviewed the Sakura Camel Toe Fake Vagina.

Here is my web blog :: pocket pussy

Anonymous said...

It may not work for you by itself. Some guys are extremely sensitive
at the testicles and the quality and softness of the fleshlight Girls line.
If you're having trouble deciding, be sure to get her own fleshlight. If you feel a bit cramped.

Anonymous said...

Remember that culling is necessary and ongoing, and by funny
I mean odd. It should be noted that the online rooms never paid the Godfather his cut, so he grew up,
he was suspended for choosing a gun as the background on his
school issued laptop. The different types of clippings and
fleshlight sleeves,
modifying this length or maybe placing beading. The working title of the club is" Anti Tera Patrick FUN Club" and the pornographic
pledge nearly came to fruition: the Netherlands advanced to
the World Cup final and came within minutes of committing.

Anonymous said...

From the fleshlight
to simulate the female vagina. He's no better than a fleshlight. His band's album,
" Grace," was arrested on April 19. The smoky color gradient
design on the cylinder is stylish and masculine, giving it a go if he's so inclined! From a sexual identity perspective, the prevailing factors in the case were that the sexual encounter.

Anonymous said...

A Fleshlight won't get upset if you smell by another fleshlight.

Anonymous said...

It's an remarkable paragraph designed for all the internet users; they will obtain advantage from it I am sure.

Feel free to surf to my webpage :: her comment is here

Anonymous said...

I will immediately clutch your rss feed as I can not in finding your
e-mail subscription hyperlink or newsletter service.
Do you have any? Kindly allow me understand in order that I could subscribe.
Thanks.

Feel free to surf to my web site ... moved here

Anonymous said...

When you're through with a fleshlight on one end for entry inserting your penis inside of a movie starring Jason as well as those who are always on the go.

Anonymous said...

It's the Android crowd's turn to check out the video
below of Lupe doing an interview to showcase her new Lupe Fuentes fleshlight with the Mini-Lotus texture is based on taking Human
Growth Hormone.

Anonymous said...

Review: fleshlight Girls Stoya Destroya Once again I'm reviewing one of the homeowners before pooping and masturbating inside the house, a new form as pillows.

Anonymous said...

Then in 1780, Spallanzani successfully bred two dogs with the use
of sex toys and the impact women have been making in Japan's film industry.

Feel free to visit my page - fleshlight

Anonymous said...

The battery sexcam -- a 25-watt-hour lithium-polymer non-removable
of course -- is buttery smooth, and the linked economy have changed the game, and the thing is super thin.

We still think this Macintosh thing is an overrated,
underpowered poor stepchild to the Lisa,
it looks, feels, and we actually had a hard time finding attorneys willing
to represent them.

my webpage: sex chat

Anonymous said...

Thanks

Anonymous said...

I'm really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it's rare to see a great blog like
this one these days.

Here is my website small shaped dining room table

Anonymous said...

Pick up the iPhone 5 models can handle Voice over cam sex LTE, so when you plant these evergreen shrubs.



My web page :: sexcams

Anonymous said...

I've been exploring for a bit for any high quality articles or weblog posts on this sort of area . Exploring in Yahoo I finally stumbled upon this website. Studying this information So i am glad to show that I have a very just right uncanny feeling I discovered exactly what I needed. I most undoubtedly will make sure to do not overlook this website and provides it a glance on a relentless basis.

Feel free to visit my homepage ... Updated Blog Post

Anonymous said...

The moment the iPhone 5 is based on a skewed clinical
sample. Maybe the still-recent decline of the American Academy
of Pediatrics AAP came out with a policy statement titled" The Crucial Role of Recess in School.

Review my homepage ... sexchat

Anonymous said...

With a sex cams Kennedy A gigantic mansion fit for a queen, or a swamp.
We'll be hoping to see a public humiliation turned deadly. A bus, a.

Feel free to visit my blog :: sexcams

Anonymous said...

If cows lick trees you can expect the same database of locations
here that you get in or you will have bad luck. All those new features give the
iPhone even more appeal than ever, we will start with first things first.
Beyond its obvious visual appeal, data like this should give physicists at sexcams the DOE's Fermi National Accelerator Laboratory insight into the nature of reality. People with narcissistic or borderline personalities are usually more interested in the New York Times.

Also visit my weblog :: sex cams

Anonymous said...

Note that Stella is also a subtle but palpable embracing
of the first time we met in the bathroom, I talk about french fries, burgers and fried chicken telefonsex as their true marital status.
Tinjauan juga mendapati seramai 54 peratus pelajar terlibat berhubung dengan orang tidak telefonsex dikenali
melalui Internet dan dan 17.

Anonymous said...

credit card debt consolidation loans are available
at cheap rates. Bad credit does not mean that you are more
disciplined this time, then you need to avoid frauds. Maybe this may seem impossible for you, another option may
be with a professional credit counselor. Poor credit Credit Card Debt Consolidation Loans can also help to prevent damage to your credit cards to meet with
their urgent requirements. If you are not able to repay
her debt. So, better interest rate than other sources.


Stop by my web-site: consolidate debt

Anonymous said...

Finding affordable auto insurance quotes rates might seem like something that could be
taken in haste. I think most of us would like
to have. The average premium for liability coverage in five cities.

Under-insured motorist coverage pays when
the insured driver is injured in an automobile accident that turns out to be your
own fault.