[NTLUG:Discuss] C pointer questions

Steve Baker sjbaker1 at airmail.net
Wed Nov 27 15:37:17 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

Nope - it'll crash - there is not enough space in b to store both
strings...it shouldn't even compile because "This is" is
a const string and b isn't - the first argument of strcat can't
be a const string).

How about:

   char b [ 100 ] ;
   strcpy ( b, "This is" ) ;
   strcat ( b, " a test" ) ;
   printf ( "%s", b ) ;

....would work much better.

---------------------------- Steve Baker -------------------------
HomeEmail: <sjbaker1 at airmail.net>    WorkEmail: <sjbaker at link.com>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sf.net    http://tuxaqfh.sf.net
            http://tuxkart.sf.net http://prettypoly.sf.net





More information about the Discuss mailing list