If u suggest calling strlen() before calling strcpy() *EVERY TIME*, u
are suggesting yet another problem. It's so easy to blow strlen().
Because it's annoying as hell.
Why not?
Please don't top-post.
Joona's point (or at least the point I would have made if I were
Joona) was that
char *p = "foo";
char q[4];
strcpy(q, p);
is *perfectly* correct, while anything along the lines of
char p[100000];
gets(p);
is *broken by design*. There's simply no possible comparison between
gets() and strcpy() as far as correctness goes.
Your response made it sound as if you thought strcpy() could possibly
copy an arbitrarily large number of characters without the programmer's
knowing about it. So (I assume) Joona mentioned the strlen() function,
which is a portable and safe way of finding out exactly *how many*
characters strcpy() is going to be copying at any time. If you can't
keep track of the length of some string yourself, strlen() is always
available.
Oh, and of course it's impossible to "blow" strlen(), unless you
suggest passing NULL or some other non-string pointer to it. Sure,
you can crash your program with
int p;
strlen((void*)&p);
any time you like. But that's just silly; I don't think you could
have been referring to that. Which leads me to the conclusion that
you were confused when you wrote
It's so easy to blow strlen().
HTH,
-Arthur