please say how to update a particular record and delete particular record from the following code:
Code:
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
struct cust
{
char name[40];
char details[40];
};
int main()
{
struct cust c;
FILE*fp;
char custname[20],choice,s;
while(1)
{
printf("1.enter customer details.\n");
printf("2. search for customer details .\n");
printf("3. exit.\n");
printf("enter ur choice\n");
choice=getchar();
switch(choice)
{
case '1':
fp=fopen("cust.txt","ab");
while (1)
{
printf("enter customer name:\n");
scanf("%s",c.name);
fflush(stdin);
printf("\nenter details:");
scanf("%s",c.details);
fwrite(&c,sizeof(c),1,fp);
fflush(stdin);
printf("\n\ndo u wnt to continue(Y/N)");
scanf("%s",&s);
if(s=='n'||s=='N')
break;
}
fclose(fp);
break;
case '2':
fp=fopen("cust.txt","rb");
printf("enter customer name:\n");
scanf("%s",custname);
while(fread(&c,sizeof(c),1,fp))
{
if(strcmp(custname,c.name)==0)
{
printf("\n\t %s\t %s",c.name,c.details);
getchar();
break;
}
else
{
printf("no details founnd:\n");
}
}
fclose(fp);
getchar();
break;
case '3':
exit(0);
}
}
getchar();
}
Comment