here i have the function that is supposed to delete a selected account and display the change in the file, but this instead removes all the account and leave only one. Can anyone help
Code:
void account_delete(char *filename)
{
int count=0,i=0,g,h;
char NAME[20];
account t[20];
FILE *file=fopen(filename,"rb");
if(file!=NULL)
{
while(fread(&t[i],sizeof (account),1,file)==1)
{
i++;
count++;
}
}
printf("give the name of account to delete");
scanf("%s",&NAME);
for( g=0;g<count;g++)
{if(strcmp(t[g].name,NAME)==0)
{ for(h=g;h<count;h++)
{
t[h]=t[h+1];
}
}
}
count--;
for(i=0;i<count;i++)
{
account_overwrite(filename,t[i]);//this open the file in "wb" and write to content of t[i] in the file. This one still works with other functions.
}
fclose(file);
view_account(filename);
}