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

I need an authoritative source/documentation for this

Towards the end of this thread here

http://www.codeguru.com/forum/showthread.php?t=293945

a poster named cma said that if we wanted to ignore the input in the
getchar() function, we could place a call to scanf just before the
getchar in this fashion and the input recieved from the getchar will
be ignored (only the next one character):

int temp;
scanf("%*c");
temp=getchar();

I want some source on the Web or some book to explain this * thing to
me and why it behaves that way. I've read K&R, and another book or two
on C but none so far have discussed this behaviour of scanf. I guess
such things are discovered through experience. I'd be grateful to
someone who could point me to some documentation that discusses this
behaviour.
Nov 14 '05 #1
3 1290
Vi****************@yahoo.com (Sathyaish) writes:
a poster named cma said that if we wanted to ignore the input in the
getchar() function, we could place a call to scanf just before the
getchar in this fashion and the input recieved from the getchar will
be ignored (only the next one character):

int temp;
scanf("%*c");
temp=getchar();


From the GNU libc manual:

The conversion specifications in a `scanf' template string have the
general form:

% FLAGS WIDTH TYPE CONVERSION

In more detail, an input conversion specification consists of an
initial `%' character followed in sequence by:

* An optional "flag character" `*', which says to ignore the text
read for this specification. When `scanf' finds a conversion
specification that uses this flag, it reads input as directed by
the rest of the conversion specification, but it discards this
input, does not use a pointer argument, and does not increment the
count of successful assignments.

[...]

I'd be surprised if this wasn't in K&R as well.
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
Nov 14 '05 #2
In <7b**************************@posting.google.com > Vi****************@yahoo.com (Sathyaish) writes:
Towards the end of this thread here

http://www.codeguru.com/forum/showthread.php?t=293945

a poster named cma said that if we wanted to ignore the input in the
getchar() function, we could place a call to scanf just before the
getchar in this fashion and the input recieved from the getchar will
be ignored (only the next one character):

int temp;
scanf("%*c");
temp=getchar();
What's wrong with

getchar(); /* discard the next character from stdin */
temp = getchar();
I want some source on the Web or some book to explain this * thing to
me and why it behaves that way. I've read K&R, and another book or two
on C but none so far have discussed this behaviour of scanf. I guess
Reading books with the brain left in neutral is a mere waste of time.
such things are discovered through experience.
They're properly documented in any good C tutorial, no need to experiment.
I'd be grateful to
someone who could point me to some documentation that discusses this
behaviour.


K&R2, pages 245-246.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #3
"Sathyaish" <Vi****************@yahoo.com> wrote in message
news:7b**************************@posting.google.c om...

I want some source on the Web or some book to explain this * thing to
me and why it behaves that way. I've read K&R, and another book or two
on C but none so far have discussed this behaviour of scanf.


K&R2 page 245 section B1.3:

"A conversion specification determines the conversion of the next input
field. Normally the result is placed in the variable pointed to by the
corresponding argument. If assignment suppression is indicated by *, as
in %*s, however, the input field is simply skipped; no assignment is
made."

--
Tim Hagan

Nov 14 '05 #4

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

Similar topics

0
by: Carlos Ribeiro | last post by:
I am looking for information on packages & import hooks, including simple examples on how to implement a simple import hook. Quick googling turns out some documents, such as: -- PEP 302:...
19
by: Fran?ois Laroche | last post by:
hey guys, I know that you will tell me that's easier to do in php or even in asp, but I just dont have the time to learn it 1- I need a javascript that will show the date of tomorrow 2- I need a...
162
by: techievasant | last post by:
hello everyone, Iam vasant from India.. I have a test+interview on C /C++ in the coming month so plz help me by giving some resources of FAQS, interview questions, tracky questions, multiple...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
85
by: | last post by:
List, I'm looking for C links for Standard C for a website targeting professional SW engineers. Intent is to have a convenient reference to Standard C, particularly for those who come from...
40
by: GTi | last post by:
Is there any source code documentation tools available for Visual Studio 2005 ? I have created a LIB that must be documented. Must I do it by hand or is it some kind of tools to pre document my...
8
by: Axter | last post by:
I normally use a program call Doxygen to document my source code.(http://www.stack.nl/~dimitri/doxygen) This method works great for small and medium size projects, and you can get good...
3
by: MC | last post by:
Where (apart from making up a lot of examples and disassembling them myself) can I get authoritative information about how strings are handled in Microsoft C#? That is, when they are interned and...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.