MM> char s[40];
MM> gets(s);
MM> puts("\r\nThis was the string you entered : "); puts(s);
AT> NO! Never! Bad! You've allocated 40 bytes, but
AT> the user could easily type 4000.
AT> use:
AT> char s[40];
AT> fgets (s, 40, stdin);
AT> printf ("\n\nThis was the string you entered: %s\n", s);
That will STILL give a case of the nasties if the user enters 40
characters. You must make room for the terminating null.
char s[41];
fgets(s,40,stdin);
* KWQ/2 1.2i *
--- FLAME v1.1
---------------
* Origin: Port Chicago's Loading Dock - 510-676-5359 (1:161/204)
|