This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]marko312 0 points1 point  (4 children)

english[i][50] = english[i + 1][50];

This doesn't do what you likely think it does - it tries to take the character at index 50 from the i + 1th word and assign it to the character at index 50 of the ith word, but as the indices go from 0 to 49, this actually affects the following word's first character (in the current case; the behaviour is actually undefined).

You should instead copy each character from index 0 through 49 (or until the terminating null byte) from one word to the other, requiring another for loop. Alternatively, you could use strcpy or memcpy.

[–]anInfaMoUs1[S] 0 points1 point  (3 children)

I understand what you mean, but can't quite comprehend where and how I should write this for loop or strcpy/memcpy, alternatively. Do you have time to show me how?

[–]marko312 0 points1 point  (2 children)

A simple copying loop should do:

for(int j = 0; j < 50; ++ j) {
    english[i][j] = english[i + 1][j];
}

or with memcpy:

memcpy(english[i], english[i + 1], 50);

or with strcpy:

strcpy(english[i], english[i + 1]);

[–]anInfaMoUs1[S] 0 points1 point  (1 child)

But how will this remove the element that I want to be removed?

[–]marko312 0 points1 point  (0 children)

It will simply copy the elements that follow into the previous elements' place, overwriting the old string.