473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("stringT emp: %s\n",stringTem p);
g_free( phrase );
phrase = stringTemp;
printf("phrase: %s\n\n",phrase) ;
}
else
{
sourceStrings.p ush_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 2832
On Apr 22, 11:48 am, clinisbut <clinis...@gmai l.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++d oes 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...@gmai l.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++d oes 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...@gmai l.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*******@gmai l.comwrote:
On Apr 22, 12:14*pm, vipps...@gmail. com wrote:
>On Apr 22, 11:48 am, clinisbut <clinis...@gmai l.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
2046
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
2337
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 them in the debugger). After encoding the string (the sameone which complete value is not visible from the debugger) all the values can be seen but they are spaced by big amounts of zeros and use more that the 2048 bytes allocated. It is like if...
1
3673
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 strings together. I'm using visual c++.net 2003. I've tried using the String class to put the image path together and then cast the String to a LPCTSTR, but that cast is forbidden. Since I'm using visual c++.net should I not be using functions like...
4
1791
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 generated is included with the code. Use & instead and it works. Dim pstrSend As String = "" 'ActionCode 1 and 2 are type BYTE, Msg is a byVal string parameter
6
2056
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
1656
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 as String Dim Surname as String Surname = String.Concat(txtSurname.Text, Chr(173)) --this one is meant to append an empty string to txtSurname) FullName = String.Concat(Surname, txtName.Text) -- now I am concatenating tha above variable and...
21
2306
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 solve in this small code, I can solve it on my own program...you don't want to have head-ache :-) So, the problem excatly is, I built an array..just like this one.
10
3477
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 separated by a hard return. For example, say I have the following 4 RTB controls in my form: RTB1 = "abcd" RTB2 = "efgh" RTB3 = "ijkl" RTB4 = "mnop"
3
2306
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 calculate the length of a string more than once; 2) never invoke realloc() multiple times if you can make do with a single malloc(). As a result, I came up with the code below. This avoids the two pitfalls above, but at the expense of needing three...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.