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);
I was just trying to reimplement "watch" for a solaris box and that bit was
puzzling me.
Conor
--
Conor Daly
Met Eireann, Glasnevin Hill, Dublin 9, Ireland
Ph +353 1 8064217 Fax +353 1 8064275
------------------------------------
9:16am up 23 days, 18:27, 5 users, load average: 1.01, 1.01, 1.00
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!