E2FINISH - #include<stdio.h> #...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<string.h> # #define max 10 /*RISHI AGARWAL 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+"); fseek(s, SEEK_SET, 0);
Background image of page 1

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

View Full DocumentRight Arrow Icon
} 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; } } } if(y==1) { printf("The customer details are \n"); printf("Id:%d\n",q[z]->cid); printf("Name:%s\n",q[z]->name);
Background image of page 2
Image of page 3
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 / 7

E2FINISH - #include&lt;stdio.h&gt; #...

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

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