Thread: integer concatenation with string again...

  1. #1
    Unregistered
    Guest

    integer concatenation with string again...

    guys...i want to ask this again...

    regarding the concatenation of integer with a string...
    i still get a SEGMENTATION FAULT ERROR!!!

    i already calloc(ED) the string...why is this happening? thanks again...

    what i did is

    void sendMessage (char ........end, char *host, int port)
    {
    printf ("it reached this part"); //it reached this part but a
    //segmentation fault occured on the next line
    sprintf (ssend,"%s:%d:%s",host,port,ssend)
    while (1)
    {
    rd = sendto(....)
    }
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Make sure ssend is calloc()'ed big enough to hold the string.

    It should have at least enough space for concatenating: host+port+ssend+3

    2 extra for the colons.
    1 extra for string terminator.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I just noticed something.

    sprintf (ssend,"%s:%d:%s",host,port,ssend)

    I don't think you can use the same string for one of the sources and the destination (ssend).

    Create a new string, for example:

    char temp[80];
    sprintf (temp,"%s:%d:%s",host,port,ssend)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Integer to string?
    By Blackroot in forum C++ Programming
    Replies: 2
    Last Post: 02-23-2006, 06:13 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM