[NTLUG:Discuss] C pointer questions
Rusty Haddock
rusty at fe2o3.lonestar.org
Wed Nov 27 13:23:55 CST 2002
Paul Ingendorf wrote:
>>From what I read in the question you are looking for the strings functions
>
>#include <string.h>
>
>char *a = " a test.", *b = "This is";
>b = strcat( b, a );
>printf(b);
>
>Should print:
>This is a test
It's very doubtful this would work. You're causing strcat() to exceed
the boundaries of what "b" is pointing to unless there's just happens
to be some user data area after the "This is" string. This should
prevent the exception signal in many environments. In others, the
string constants above could be linked to read-only memory and then
you're really up string creek. :-)
strcat() does not allocate new memory for its result. The assignment
of the return value of strcat() is rather superfulous. The man page
for strcat(3), which isn't more than a large screen-full, explicitly
states this. Nonetheless, this is bad technique.
-Rusty-
--
_____ Rusty Haddock = KD4WLZ = rusty at fe2o3.lonestar.org
|\/ o \ o
| ( -< O o The day Microsoft makes something that doesn't suck
|/\__V__/ is the day they start making vacuum cleaners.
More information about the Discuss
mailing list