LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] C string concat question ??

[ILUG] C string concat question ??

Sean McGrath - Sun Microsystems Ireland sean.mcgrath at sun.com
Thu May 3 10:50:21 IST 2001


Kenn Humborg stated:
< > On Wed, May 02, 2001 at 06:09:29PM +0100 or thereabouts, Kenn 
< > Humborg wrote:
< > >    msg = malloc(strlen(strvar1) + strlen(strvar2) + 1);
< > >    if (msg == NULL) {
< > >        /* argh */
< > >    } else {
< > >       strcpy(msg, strvar1);
< > >       strcat(msg, strvar2);
< > >    }
< > 
< > and if you've a variable number of variables to concat like argv[*] you
< > could go with
< > 
< > MSG_SIZE=1;
< > for (i=0; i<argc; i++) {
< >   MSG_SIZE += strlen(argv[i]);
< > }
< > 
< > msg = malloc(MSG_SIZE);
< 
< Sigh...
< 
<    msg = malloc(MSG_SIZE+1);

  err, isn't that why hes set MSG_SIZE=1; at the start ????

< 
< Later,
< Kenn
< 
< 
< -- 
< Irish Linux Users' Group: ilug at linux.ie
< http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
< List maintainer: listmaster at linux.ie

-- 
Sean.
.
At the mo its Incognito Pieces Of A Dream




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell