char* linker

Started by
10 comments, last by programering 21 years ago
quote:Original post by programering
char *adress;
adress = (char *)malloc(sizeof(path) + sizeof(name) + sizeof(format));


It should be

adress = (char *)malloc(sizeof(path) + sizeof(name) + sizeof(format)+1);

because C strings need an additional character for 0 termination
Advertisement
quote:Original post by noVum
It should be

address = (char *)malloc(sizeof(path) + sizeof(name) + sizeof(format)+1);

because C strings need an additional character for 0 termination

It should be strlen instead of sizeof, because the length of strings can not be statically determined outside of their declaration scope (at which point programmatically determining size is always unnecessary).

This topic is closed to new replies.

Advertisement