Results 1 to 5 of 5

Thread: Combining to char arrays (very easy question)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176

    Combining to char arrays (very easy question)

    let's say i want to combine CharArray1 and CharArray and i want to add "hi this is a string" aswell. How should i do this. From what i understand now i need to count the space i need, make a new array and fill it. I dont have a clue how to (the filling).

    Thnx
    JpEgy

  2. #2
    amac
    Guest
    Here is an example.

    Code:
        char szString1[] = "First character array";
        char szString2[] = "Second character array";
    
        char * lpszFullString = NULL;
    
        lpszFullString = new char[ strlen( szString1 ) + strlen( szString2 ) + strlen( "Third String" ) + 1 ];
    
        strcpy( lpszFullString, szString1 );
        strcat( lpszFullString, szString2 );
        strcat( lpszFullString, "Third String" );
    
        std::cout << lpszFullName << std::endl;
    
        delete [] lpszFullName;

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    thnx dude that really helped. I got it working perfectly now except for 1 tiny /n that i should get ridd off. If i remember corectly there's a function to remove it from the end of a string right? I couldn't find it though.... I already tried to do it with substrings (that's how i did it with VB ) Do you know a good way?

    Thnx!
    JpEgy

  4. #4
    amac
    Guest
    Remove the end?

    Code:
        char szString[] "MacDonald, Andrew
        char szStrToRemove[] = "An";
    
        char * lpszTemp = strstr( szString, szStrToRemove );
    
        if( lpszTemp )
            *lpszTemp = '\0';
    
        std::cout << szString << std::endl;

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    Oki i found it myself (took me a few hours, lol)

    szString = strtok (szString,"\n");

    that's what i needed , thnx anyway
    JpEgy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width