void searchFile()
{
int choice;
FILE *ptr;
record p;
char search[20];
if((ptr=fopen("PRODUCTS2.txt","r"))==NULL)
{
printf("File cud not be opened\n");
}
else
{
printf("Enter name of product\n");
scanf("%s",&search);
while(!feof(ptr))
{
if(strcmp(p.name,search)==0)
{
printf("%i%f%i",p.id,p.price,p.quantity);
fscanf(ptr,"%i%f%i",p.id,p.price,p.quantity);
}
else
{
printf("Product not found\n");
}
}
}
}
And record is a datatype :
struct Record
{
char id[10];
char name[20];
float price;
char category[15];
int quantity;
};
If anyone can help me to generate a "delete" function which asks the user for the id and deletes it , i wud infinitly be grateful.


Sign In
Create Account


Back to top









