Boy
Scanf is used for decoding formatted text. It performs simple lexical analysis
and text to value conversions based on the specification given to it in the
format string. Scanf can easily scan digits representing and integer integer
and convert it to a value.
A successful call to Getchar reads a single character from the standard input
and returns it as an int value.
Getchar is a much more fundamental and ``primitive'' operation, and can be
used to construct efficient scanners that are more powerful than scanf(). On
the flipside, emulating some of the functionality of scanf with getchar()
would require quite a bit of work, and the involvment of other library
functions.
Mixing the use of getchar() and scanf() in the same program can be tricky.
The comp.lang.c FAQ has some discussion about scanf() that you might find
useful.
--
Boy, are you in the wrong newsgroup, Boy!
comp.std.c discusses the upcoming update to the ISO C language
standard. If you want to ask questions like this, please post
to comp.lang.c, which is about programming with the current
standard C language.
Jack
Roughtly in terms of the standard, scanf must work as if it uses getc and
getchar is a short form from getc( stdin ). So scanf is essentially the
higher level function. As to when you should use which one, the standard
does not tell you that. That is a question for a programming group such
as comp.lang.c or a book on C programming.
[comp.std.c is for C standardization issues.]
--
Stephen Baynes MBCS CEng Stephen...@soton.sc.philips.com
Philips Semiconductors Ltd
Southampton SO15 0DJ +44 (01703) 316431
United Kingdom My views are my own.
Do you use ISO8859-1? Yes if you see © as copyright, ÷ as division and ½ as 1/2.
s97...@mailserv.cuhk.edu.hk wrote in article
<61im8m$o...@eng-ser1.erg.cuhk.edu.hk>...
> Can anyone tell me the difference between getchar and scanf. both of them
> get information from the user but when should we use which one and which
one
> is better in what situation?? pls tell me!
>
> Boy
>