|
From: Daniel K. O. <dan...@ya...> - 2003-04-04 03:48:06
|
> 1-Why does gcc for unix tell me "gets" is a dangerous function?
Simple answer: buffer overflow. Look at fgets.
> 2-What exactly is the difference
> between the <ENTER> key stroke of unix and
> of windows? I often have problems with it when I read two
> consecutive values
> for example: for(i=0;i<5;i++) scanf("%c",&a);
> In the example above, I've tried to use "fflush(stdin), but it seemed to
> have no effect. The one thing that worked fine was something
> like: for(i=0;i<5;i++) { scanf("%c",&a);
> getchar(); //strange getchar(). Would it be to read some extra
> character of the Unix <ENTER>? }
Ioannis said to me once: "fflush empties output buffers, not input". sscanf
doesn't read the remaining '\n'. You should use fgets to read a line
(including the '\n', no need to fflush anything), then sscanf what you need
inside the string.
Daniel K. O.
It's OK to be ignorant; it's not OK to play stupid.
http://www.catb.org/~esr/faqs/smart-questions.html
|