From: Martin Donlon (akawaka at domain csn.ul.ie)
Date: Thu 03 May 2001 - 00:18:50 IST
glib has some really great utility functions for stuff liek this. But I
find it hard to add glib as a requirement for non gtk app. So, I usually
just pull out what I need and keep it in my own little snippet store. A
useful function for joining strings:
char *strconcat(char *start_string, ...){
int len;
va_list args;
char *str, *result;
len = strlen( start_string ) + 1;
va_start( args, start_string );
while( ( str = va_arg( args, char* ) ) )
len += strlen( str );
va_end( args );
result = malloc( sizeof( char ) * len );
strcpy( result, start_string );
va_start( args, start_string );
while( ( str = va_arg( args, char* ) ) )
strcat( result, str );
va_end( args );
return result;
}
On Wed, May 02, 2001 at 05:58:59PM +0100, Glen Gray wrote:
> Looking for a simple way to cat two strings into a third.
>
> I had the following in my code
>
> msg = strdup(strcat(strvar1, strvar2));
>
> What happens here is the strvar2 is concatinated to strvar1 and a
> pointer to strvar1 is returned to strdup which allocates memeory for the
> char *message variable.
>
> What I want is that functionality without strvar1 being modified. I
> would rather not have to create my own buffer and do it over two lines.
>
> I thought this was interesting as I couldn't see and alternative to
> strcat. Hope someone else can.
>
> Glen
>
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at domain linux.ie
-- Martin -- Bother! said Pooh, and twitted Cal Webster.
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:09 GMT