Strcat function not executing properly?

I have 20 string inside a 2D array. I must concatenate the first 20 strings by twos and leave the last 8 alone. Final would be 10 strings. I have successful concatenate the 20 but the final 8 string aren't there. Where did the final 8 string go?

Last edited on
I don't see anything wrong with the code you posted. Though logically... if you are halving the number of strings, you should end up with 104 strings, not 108.
No but I concatenated 200 out of 208. get 100. The 8 are left unconcatenate. But I can't find these 8. Right now. I get 104 strings because it's concatenating all the strings. If I change it to i<200. It only does the first 200 but the last 8 are missing.
Last edited on
Okay I get it.

Take a closer look at your while loop on line 9. That loop basically erases all strings after the ones you concatenated. So if you change the first loop to only join 200 strings, then the remaining strings will get wiped by that next loop.
So I just modify the while loop to what?
Last edited on
Think about what you have and what you need to get done.

What you have at the start of this code:
1) dest[0] - dest[207] contain the original strings

What you have accomplished after the first for loop:
1) dest[0] - dest[99] contained joined strings
2) dest[100] - dest[207] contain the original unjoined strings

Your goal:
1) dest[0] - dest[99] contain joined strings
2) dest[100] - dest[107] contain the last 8 original, unjoined strings
3) dest[108] - dest[207] are wiped empty

So stop writing code for a second... and think about what needs to be done... logically... to move from what you have to what you need. Once you have the logic understood... then write the code to do it.
I would need another loop in between the two one I already have.
A for loop that starts at 100 loops till 107.
Last edited on
Yup. good job ;)
What would be inside the loop?
What does the loop need to accomplish? Work out the logic.
Last edited on
Copy two into one using strcpy() I got it to work!
Thanks for the help.
Last edited on
Not quite. You're not combining the last 8 strings, right? You're just moving them from the last 8 positions to positions [100] through [107]
I have two indexes, loop till max_s_rows increment both indexes and strcpy dest[j] des[i]. It worked fine. I'm not sure what you mean?
Okay I just misunderstood. You said "copy two into one" which made me think you were combining strings. But it sounds like you are just "copying one into a different one" which is the right thing to do.

So yeah... communication error. Glad it's working. :)
Thanks. Have a good one.
Topic archived. No new replies allowed.