[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: getc() and fgetc()



On Mon, 26 Mar 2001, Ketu wrote:

> These things happened when i started programming, in the first year, why i
> got this thing now was because i read recently that scanf skips white spaces
> and can go into infinite loop if it cannot scan what it wants, just
> reminiscent of the experiences.
> 
	IMO Nothing like that. scanf does skip white spaces. And it tries
to format the input into what has been asked to. For example if you ask
scanf to scan an integer and give it a float, it will just read upto and
not including the dot. And if you give it a character when it expected an
integer, it will simply not change the value of int variable.

	I haven't ever seen that infinite wait (or loop) problem ever
unless I do something silly (which is often the case :)

<snip source="man scanf">

RETURN VALUES
These functions return the number of input items assigned, which can be
fewer than provided for, or even zero, in the event of a matching failure.
Zero indicates that, while there was input available, no conversions  were
assigned;  typically this is due to an invalid input character, such as an
alphabetic character for a `%d' conversion.

</snip>

-- 

#!!!	If anything can go wrong, _FIX_ it. (To hell with MURPHY)
	
						Ajay kumar Dwivedi
						 ajayd@xxxxxxxxxx