Originally Posted by
anonytmouse
Given your user name, it is somewhat appropriate that your code includes:
It is rather ironic, isn't it? But I see a steady progression in most C programmers:
Code:
/* Newbie */
scanf ( "%s", string );
becomes
Code:
/* Warned about buffer overflow */
scanf ( "%1023s", string );
becomes
Code:
/* Really neat trick! */
sprintf ( fmt, "%%%ds", sizeof string - 1 );
scanf ( fmt, string );
becomes
Code:
/* Never use scanf */
fgets ( string, sizeof string, stdin );
becomes
Code:
/* Too lazy to do it right */
scanf ( "%s", string );
becomes
Code:
/* Got burned with scanf */
fgets ( string, sizeof string, stdin );
Some even go so far as to say that fgetc is the only "right" way to do it because it gives you the most control, but not many actually practice what they preach.