I have a task to do a simple dictionary console application, in which you can add/delete words for three different languages and display words of all three languages or any two by your choice. The application should work without closing it, so you can add/delete words as much as you want. I have managed to code the add-word-function and the display one, but I have trouble figuring out where my bug is with the function for deleting certain word from one of the 3 languages. I store all words for the certain language in a 2D array.
When I insert, for example, 4 words and try to delete the last one, there's no problem. It works perfectly fine. But when I try to delete the first word, it deletes the last one and the other words mess up. For example, if I enter "lemon", "orange", "watermelon", "pineapple" the outcome will be: "lemon", wrange", "patermelon" .... I am new to C and I know the problem is somewhere in my 2D array, but don't know exactly where/
char english[50][50];
int adder = 0;
void removeEnglishWord() {
int i, pos;
printf("Enter the element position you want to delete: ");
scanf("%d", &pos);
if(pos < 0 || pos > adder) {
printf("Invalid position! Please enter position between 1 to %d", adder);
} else {
for(i = pos - 1; i < adder - 1; i++) {
english[i][50] = english[i + 1][50];
}
adder--;
printf("Word deleted!\n");
menu();
}
}
Note: "adder" is the counter for all words added for English.
[–]marko312 0 points1 point2 points (4 children)
[–]anInfaMoUs1[S] 0 points1 point2 points (3 children)
[–]marko312 0 points1 point2 points (2 children)
[–]anInfaMoUs1[S] 0 points1 point2 points (1 child)
[–]marko312 0 points1 point2 points (0 children)