/* diskex1.c */ #include #include #define RECSIZE 21 int begin(char* dest, char* src); int process(char* dest, char* src); int finish(char* dest, char* src); static FILE *output; static int write_count = 0; struct { /* struct for customer data */ char number[5]; char name[30]; } customer [9]; int begin(char* d, char* s) { output = fopen("diskex1.dat","w"); if (output == NULL) { strcpy(d, "File open ERROR "); return 0; } else { strcpy(d,"File opened SUCCESSFULLY "); return 0; } *s=NULL; return 0; } int finish(char* d, char* s) { fclose(output); sprintf(d,"File closed successfully %d records written", write_count); *s=NULL; return 0; } int process(char* d, char* s) { int rcount = 1; int acount = 0; char temp[RECSIZE] = ""; if (strlen(s) > RECSIZE -1) { strcpy(d, "Data too long ...: "); strcat(d, s); return 0; } strcpy(temp, s); acount = fwrite(temp, sizeof(temp), rcount, output); if (acount != rcount) { strcpy(d, "Error writing record: "); strcat(d, temp); return 0; } strcpy(d, "Record written successfully"); write_count++; return 0; }