C
clinisbut
I'm not sure if this is the right group, but I didn't found any other
more appropiate to post my problem.
I'm trying to concatenate chars using the Glib library and I'm getting
strange behaviours.
This is my code:
int num_chars = strlen( text );
vector< gchar* > sourceStrings;
gchar* stringTemp;
gchar* phrase = NULL;
for( int i=0; i<num_chars; i++ )
{
if( text!='\n' )
{
stringTemp = g_strconcat( phrase, text, NULL );
printf("stringTemp: %s\n",stringTemp);
g_free( phrase );
phrase = stringTemp;
printf("phrase: %s\n\n",phrase);
}
else
{
sourceStrings.push_back( phrase );
g_free( phrase );
phrase = NULL;
}
}
Variable "text" is a gchar*.
g_strconcat should allocate a new gchar* with all strings passed
concatenated.
What I'm getting is g_strconcat is not concatenating anything, and
stringTemp is empty at first printf (null).
I think the problem comes from variable text, 'cause I test with this:
stringTemp = g_strconcat( "hello", text, NULL );
And this throws me an error at runing time, something related with
strlen().
more appropiate to post my problem.
I'm trying to concatenate chars using the Glib library and I'm getting
strange behaviours.
This is my code:
int num_chars = strlen( text );
vector< gchar* > sourceStrings;
gchar* stringTemp;
gchar* phrase = NULL;
for( int i=0; i<num_chars; i++ )
{
if( text!='\n' )
{
stringTemp = g_strconcat( phrase, text, NULL );
printf("stringTemp: %s\n",stringTemp);
g_free( phrase );
phrase = stringTemp;
printf("phrase: %s\n\n",phrase);
}
else
{
sourceStrings.push_back( phrase );
g_free( phrase );
phrase = NULL;
}
}
Variable "text" is a gchar*.
g_strconcat should allocate a new gchar* with all strings passed
concatenated.
What I'm getting is g_strconcat is not concatenating anything, and
stringTemp is empty at first printf (null).
I think the problem comes from variable text, 'cause I test with this:
stringTemp = g_strconcat( "hello", text, NULL );
And this throws me an error at runing time, something related with
strlen().