473,378 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

concatenating strings

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[i]!='\n' )
{
stringTemp = g_strconcat( phrase, text[i], 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[i], NULL );

And this throws me an error at runing time, something related with
strlen().
Jun 27 '08 #1
4 2813
On Apr 22, 11:48 am, clinisbut <clinis...@gmail.comwrote:
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:
<C++ code snipped>

Amazing, a programmer who doesn't know what language he uses :-).
This newsgroup discusses C. Your code is (most likely) C++. However,
<comp.lang.c++does not seem appropriate as only standard C++ is
discussed there. I don't know where to direct you, but you could wait
for Mr Twink, he has a bad habit of answering the most off-topic
questions.
Jun 27 '08 #2
On Apr 22, 12:14*pm, vipps...@gmail.com wrote:
On Apr 22, 11:48 am, clinisbut <clinis...@gmail.comwrote: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:

<C++ code snipped>

Amazing, a programmer who doesn't know what language he uses :-).
This newsgroup discusses C. Your code is (most likely) C++. However,
<comp.lang.c++does not seem appropriate as only standard C++ is
discussed there. I don't know where to direct you, but you could wait
for Mr Twink, he has a bad habit of answering the most off-topic
questions.
I know there is some C++ code there, but my question relates uniquely
to C (Glib is "plain" C), so I wrote here this topic.
As you can see I don't ask anything about std::vector (I think is the
only C++ part in my code), that could give you a reason about
redirecting me to comp.lang.c++. I know this group only discuss C
standard, but as I said, I didn't found any better appropiate group to
post my doubt, so I'm sorry if my problem bothers you
Jun 27 '08 #3
clinisbut wrote, On 22/04/08 11:42:
On Apr 22, 12:14 pm, vipps...@gmail.com wrote:
>On Apr 22, 11:48 am, clinisbut <clinis...@gmail.comwrote: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:
<C++ code snipped>

Amazing, a programmer who doesn't know what language he uses :-).
This newsgroup discusses C. Your code is (most likely) C++. However,
<comp.lang.c++does not seem appropriate as only standard C++ is
discussed there. I don't know where to direct you, but you could wait
for Mr Twink, he has a bad habit of answering the most off-topic
questions.

I know there is some C++ code there, but my question relates uniquely
to C (Glib is "plain" C), so I wrote here this topic.
As you can see I don't ask anything about std::vector (I think is the
only C++ part in my code), that could give you a reason about
redirecting me to comp.lang.c++.
So why didn't you simply remove the C++ code? Otherwise how are we to
know that C++ is not doing something strange?
I know this group only discuss C
standard, but as I said, I didn't found any better appropiate group to
post my doubt, so I'm sorry if my problem bothers you
You could try the Gnome development forum since Glib is I believe part
of the Gnome project http://gnomesupport.org/forums/
Alternatively check what mailing lists exist.
--
Flash Gordon
Jun 27 '08 #4
On 2008-04-22, clinisbut <cl*******@gmail.comwrote:
On Apr 22, 12:14*pm, vipps...@gmail.com wrote:
>On Apr 22, 11:48 am, clinisbut <clinis...@gmail.comwrote: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:

<C++ code snipped>

Amazing, a programmer who doesn't know what language he uses :-).
This newsgroup discusses C. Your code is (most likely) C++. However,
<comp.lang.c++does not seem appropriate as only standard C++ is
discussed there. I don't know where to direct you, but you could wait
for Mr Twink, he has a bad habit of answering the most off-topic
questions.

I know there is some C++ code there, but my question relates uniquely
to C (Glib is "plain" C), so I wrote here this topic.
Regardless of the C code, you're using a C++ compiler.

--
Russell Wood
<http://www.dynode.net/~rjw/>
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dont bother | last post by:
Hey, I have these attributes: index which is a numerical value value vector which is a numerical float value and I want to concatenate like this:
4
by: Juan | last post by:
Does any one know if there are reported bugs when concatenating strings? When debugging each variable has the correct value but when I try to concatenate them some values are missing (I canīt see...
1
by: ebobnar | last post by:
I need to call the function LoadImage which take a LPCTSTR argument to specify the path to the image to load. However, I need to create this path dynamically from user input by concatenating...
4
by: FB's .NET Dev PC | last post by:
Interesting note, the code below as is will attempt to cast what is clearly indicated as a string into a double. This is becuase the use of + as a concatenation operator. The error message...
6
by: Hennie7863 | last post by:
Hi, I have table which has the following values : ID SEQ Text 1 1 A 2 1 B 3 2 C 4 2 D 5 2 E
4
by: lindiwemaduna | last post by:
I want to concatenate values of two text boxes into one string but these should be separated by a space in the database table. i have tried all the following but twas not successful: Dim fullName...
21
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to...
10
by: Neil | last post by:
Using the MS Rich Textbox Control 6.0 in Access 2000, I need to concatenate several RTB controls into a single RTF file. Sometimes two strings will be side-by-side; other times they need to be...
3
by: Big Brother | last post by:
I've been thinking about the seemingly simple task of writing a va_arg-type function to concatenate arbitarily many strings. My first thoughts violated the following principles: 1) never...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.