E2FINISH PRINTOUT - #include#include#definemax10*RISHIAGARWAL FILEHANDLING ROLLNO02 SECMPNA structcustomer cfw intcid

Info iconThis 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)++;    {fclose(s);     s = fopen("cust1.txt", "w+");
Background image of page 1

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

View Full DocumentRight 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;}    }   }
Background image of page 2
  if(y==1)   {     printf("The customer details are \n");
Background image of page 3

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

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

This note was uploaded on 10/25/2010 for the course CMPN SEM3 taught by Professor Thakur during the Fall '07 term at University of Mumbai.

Page1 / 8

E2FINISH PRINTOUT - #include#include#definemax10*RISHIAGARWAL FILEHANDLING ROLLNO02 SECMPNA structcustomer cfw intcid

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online