|
From: Ioannis V. <iv...@em...> - 2003-04-04 03:52:44
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Juliano P=E1vel Brasil Cust=F3dio
> Sent: Thursday, April 03, 2003 4:18 PM
> To: Dev-Cpp-Users (dev...@li...
> Subject: [Dev-C++] c on unix
>=20
>=20
> Hello to everybody. I know this isn't a pure c/c++=20
> programming list (it
> s more a c++ plus dev-c++ programming list, right?) but maybe=20
> some of you
> could help me with this:
>=20
> 1-Why does gcc for unix tell me "gets" is a dangerous function?
Because you can't limit the input to the characters that the provided =
buffer
can hold. Example:
#include <stdio.h>
/* ... */
chas s[10];
/* imagine that you enter 50 characters... */
gets(s);
>=20
> 2-What exactly is the difference between the <ENTER> key=20
> stroke of unix and
> of windows? I often have problems with it when I read two=20
> consecutive values
> for example:
>=20
> for(i=3D0;i<5;i++)
>=20
> scanf("%c",&a);
>=20
> In the example above, I've tried to use "fflush(stdin),=20
> but it seemed to
> have no effect.=20
fflush(stdin); is not portable (is not guaranteed to work). fflush() is
intended for *output* streams.
The one thing that worked fine was something like:
>=20
> for(i=3D0;i<5;i++)
>=20
> {
>=20
> scanf("%c",&a);
>=20
> getchar(); //strange getchar(). Would it be to read some extra
> character of the Unix <ENTER>?
>=20
> }
getchar() reads a character including '\n' (*after* '\n' has been =
entered).
In the above code, '\n' remains in the stream (scanf() doesn't read the
'\n').
>=20
> I hope my second doubt isn't too confusing.
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
|