concatenating strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • clinisbut

    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().
  • vippstar@gmail.com

    #2
    Re: concatenating strings

    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.

    Comment

    • clinisbut

      #3
      Re: concatenating strings

      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

      Comment

      • Flash Gordon

        #4
        Re: concatenating strings

        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

        Comment

        • Russell Wood

          #5
          Re: concatenating strings

          On 2008-04-22, clinisbut <clinisbut@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/>

          Comment

          Working...