I want to remove the i-th member of a string array, and bring every member which comes after it one place prior (the i+1-th member to i and so on). I came up with the following code:
for (int j = i; j < arrSize - 1; j++) {
strcpy(members[j],members[j+1]);
}
free(members[arrSize-1]);
But that got me thinking that it might be wrong. For example, if the i-th place member contains the name "John", while the (i+1)-th place members contains the name "Joshua", which means each string is in a different length, would there be any memory leaks or any problem? Thanks in advance!
EDIT: The definiton of members:
members = malloc(maxMembersNum * sizeof(char*));
string array? I mean, show us the definition ofmembers.members?membersand how it's built. C has multiple ways to do this.free(members[i]);for (int j = i; j < arrSize - 1; j++) { members[j] = members[j+1]; }`arrSizeis actually a size then the code has a buffer overflow on the last iteration of the for-loop, and it should bearrSize-2in the for-loop