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

Re: Fw: Infinite Joy Ride(example)

On Tue, 10 Apr 2001 10:40:56 GMT
kamesh jayachandran <kameshj@xxxxxxxxxxxxx> wrote:

> hai,
> It is the simple program that is given as an example to 
> illustrate random file handling in "C For Linux Programming"
> The program works well if numeric values are given.If I 
> give non numeric value say 'A'.It goes for infinite joy 
> ride and the value of offset still remains at the value 
> that I have given before giving the non numeric value.
> After invalid input scanf fails to scan anymore and if I 
> try to print the value of offset in if and else if prints 
> the address of offset not the value.

This is normal beheviour of the 'C'. If you want your program not to crash
in such situations then you should use tokeniser and then string

That is read input as string. Convert it in parts. Then use 'atof','atoi'
etc to get your numeric inputs.

if you want int(a,b); then you will be assuming input in form

You should seperate it in two strings 13123 and 2323 and then convert to
required form.

If you expect numeric input from keyboard and read it by scanf(..) and
user presses any function key your prog will colapse.

Deepak Joglekar
/( )\
 ^ ^