Monday, October 29, 2007

strlen() vs. sizeof() Tip

Only use sizeof() for locally allocated buffers.
Always use strlen() for variables passed from outside.

Why: using sizeof() with a pointer to char passed to you will return
the size of the pointer itself (which is 4 always) not the size of the
allocated space to that buffer.

No comments:

Post a Comment