{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E2FINISH PRINTOUT -...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<string.h> #define max 10 /*RISHI AGARWAL FILE HANDLING   ROLL NO 02   SE CMPN A */ struct customer {  int cid;  char name[30]; }; int dl; void add(FILE *s, int *c) {  struct customer *p,*q[10];  int i,y=0;   if(*c<(max-1))   {p=(struct customer *)malloc(sizeof(*p));   printf("Enter The customer ID:");   scanf("%d",&p->cid);   printf("Enter The customer NAME:");   scanf("%s",p->name);   fseek(s, SEEK_SET, 0);   fread(&q,  sizeof(q), 1, s);   for(i=0;i<=*c;i++)   {if(p->cid==q[i]->cid)    {printf("The customer id already exists\n");     y=1;     break;}   }   if(y==0)   {for(i=0;i<=*c;i++)    {if(strcmp(p->name,q[i]->name)==0)     {printf("The customer name already exists\n");      y=1;      break;}    }   }   if(y==0)   {    (*c)++;    if((*c)==-1&&dl==1)    {fclose(s);     s = fopen("cust1.txt", "w+");
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
    fseek(s, SEEK_SET, 0);}     else    {fseek(s, SEEK_SET, 2);}    fwrite(&p, sizeof(p), 1, s);}  }   else{printf("Array is full");} } FILE * del(FILE *s, int *c) {  struct customer *p,*q[10];  int i,y=0,z;  FILE *d;   if(*c==-1)   {printf("Array is empty\n");    return NULL;}   p=(struct customer *)malloc(sizeof(*p));   printf("Enter The customer ID:");   scanf("%d",&p->cid);   fseek(s, SEEK_SET, 0);   fread(&q,  sizeof(q), 1, s);   for(i=0;i<=*c;i++)   {    if(p->cid==q[i]->cid)    {y=1;     z=i;     break;}   }   if(y==0)   {    printf("The customer id does not exist");    printf("\nEnter the customer name to be deleted");    scanf("%s",p->name);    for(i=0;i<=*c;i++)    {     if(strcmp(p->name,q[i]->name)==0)     {y=1;      z=i;      break;}    }   }
Image of page 2
  if(y==1)   {     printf("The customer details are \n");     printf("Id:%d\n",q[z]->cid);
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern