There is a problem on my homework assignment that I am just drawing blanks for. It seems easy, but I just dont see what it is asking. Anyone have any idea how to do this following problem?
The following C function removes structures from an array. It has three parameters:
the array of structs, the array of those to be removed, and the size of the two arrays.
The function does not remove any that should not be removed, but sometimes does
not remove all the structs that it should. Fix the function, and write up what the
problem was.
void RemoveUnused(Component *cmp, char *rlist, int count){
int i, j;
for(i = 0; i < count; i++){
if(rlist){
for(j = i + 1; j < count; j++){
cmp[j-1] = cmp[j];
rlist[j-1] = rlist[j];
}
count--;
}
}
}
The following C function removes structures from an array. It has three parameters:
the array of structs, the array of those to be removed, and the size of the two arrays.
The function does not remove any that should not be removed, but sometimes does
not remove all the structs that it should. Fix the function, and write up what the
problem was.
void RemoveUnused(Component *cmp, char *rlist, int count){
int i, j;
for(i = 0; i < count; i++){
if(rlist){
for(j = i + 1; j < count; j++){
cmp[j-1] = cmp[j];
rlist[j-1] = rlist[j];
}
count--;
}
}
}
