[NTLUG:Discuss] C pointer questions

Paul Ingendorf pauldy at wantek.net
Wed Nov 27 16:36:53 CST 2002


It does work I've used it many a time.  If you have a better way of doing it 
please share.  Otherwise your comment about it being bad technique is out of 
line.  If you think it won't work then try it in a gcc compiler before telling 
how it won't.

Quoting Rusty Haddock <rusty at fe2o3.lonestar.org>:

> 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.
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
> 



-- 
-->> mailto:pauldy at wantek.net
-->> http://www.wantek.net/
Running ....... Cos anything else would be a waste...
`:::\'                  .......  ......
 :::  *                  `::.    ::\'
 ::: .::  .:.::.  .:: .::  `::. :\'
 :::  ::   ::  ::  ::  ::    :::.
 ::: .::. .::  ::.  `::::. .:\'  ::.
:::.....................::\'   .::::..




More information about the Discuss mailing list