I am looking for a way to delete an entry from an array in C. Also delete an entry in a structure.
I am pretty new to C, any idea how to do it?
UPDATE:
Found a code that is supposed to delete an entry from a structure:
void removeEntry(student *st, int *nr, char nu[50])
{
int k=0,i,j;
for(i=0;i<*nr;i++)
{
if(strcmp((st+i)->name,nu)==0)
{
k++;
for(j=i;j<(*nr-k);j++)
{
*(st+j)=st[j+1];
}
}
}
*nr=*nr-k;
}
To delete an entry in a dynamically allocated array (replace
Tby the actual type stored in the array):If order doesn’t matter, then replace the
memmovewitht[i] = t[n-1];There’s no way to remove a member from a
struct.