please can anyone look at the problem of this program
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
typedef struct account
{
char name[20];
char password[20];
char previleges[20];
}account;
void account_write(char *);
void fill_account(account);
void account_search(char *);
void print_account(account [],int);
void view_account(char *,int n);
void print_file(account [],int);
void account_delete(char *);
int main(){
account c;
int n;
char *filename="account.txt";
// account_write(filename);
//account_search(filename);
//view_account(filename,n);
account_delete(filename);
getch();
return 0;
}
void fill_account(account *c)
{
printf("give the name of account");
scanf("%s",&c->name);
printf("give the password");
scanf("%s",&c->password);
printf("give previliges");
scanf("%s",&c->previleges);
}
void account_write(char *filename)
{
FILE *file=fopen(filename,"ab");
fflush(file);
if(file!=NULL)
{
account temp;
fill_account(&temp);
fwrite(&temp,sizeof (temp),1,file);
}
fclose(file) ;
}
void account_search(char *filename)
{int count=0,i=0;
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");
scanf("%s",&NAME);
for(int j=0;j<count;j++)
{
if(strcmp(t[j].name,NAME)==0)
printf("%s \t %s\t %s \t",t[j].name,t[j].password,t[j].previleges);
}
fclose(file);
}
void account_delete(char *filename)
{
int count=0,i=0;
char NAME[20];
account t[20];
FILE *file=fopen(filename,"wb");
if(file!=NULL)
{
while(fread(&t[i],sizeof (account),1,file)==1)
{
i++;
count++;
}
}
printf("give the name of account");
scanf("%s",&NAME);
for(int g=0;g<count;g++)
{if(strcmp(t[g].name,NAME)==0)
{ for(int h=g;h<count;h++)
{
t[h]=t[h+1];
}
}
}
count--;
print_file(t,count);
fclose(file);
}
void print_file(account t[30],int n)
{
for(int i=0;i<n;i++)
{ printf("%s",t[i].name); }
}