const char* and char* concatenation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randysimes
    New Member
    • Oct 2009
    • 54

    const char* and char* concatenation

    I am trying to concatenate these two items and I get an error about binary conversion.
    This is how I have it set up:
    bool concatenate (const char* foo, char* bar)
    const char* foobar = foo + bar
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    foo and bar are addresses of characters. You are trying to add addresses and this makes no sense. You need to work with contents of these strings and not their addresses.

    What you need to so is:

    1) count the number of characters in the string foo.
    2) count the number iof characters in the string bar.
    3) allocate memory for a char array for foo+bar+1 characters
    4) strcpy foo to your new array
    5) strcat bar to your new array
    6) free your array when you are done with it.

    Comment

    Working...