Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
void readNUMBER(void) { FILE *employee; struct employeeRecord query; int record, x; long offset; char *name, *address; /*get record # */ printf("Which record do you want to find? "); scanf("%d", &record); /*open file */ employee = fopen("employeeRecords", "r"); if(employee == NULL) { printf("Error opening file.\n"); return; } /^seek to the record onfile */ offset = (long)(record-1)*sizeof(query); x = fseek(employee, offset, SEEK_SET); if(x != FALSE) { printf("Error reading from file!\n"); return; } /*read the record into memory */ x = fread(&query, sizeof(query), 1, employee); if(x == FALSE) { printf("Error reading record!1\n"); return; } /*malloc space for the strings stored outside of the structure on file */ name = (char *) malloc( sizeof(char) * query.nameLength); if (name == NULL) exit (1); address = (char *) malloc( sizeof(char) * query.addressLength); if (address == NULL) exit (1); /*Seek to the name string */ offset = (long)(record-1)*sizeof(query)+sizeof(query); x = fseek(employee, offset, SEEK_SET); if(x != FALSE) { printf("Error reading from file!\n"); return; } /*Read name into memory */ x = fread(&name, query.nameLength, 1, employee); if(x == FALSE) { printf("Error reading record!2\n"); return; } /*Seek to address */ offset = (long)(record-1)*sizeof(query)+sizeof(query)+query.nameLength; x = fseek(employee, offset, SEEK_SET); if(x != FALSE) { printf("Error reading from file!\n"); return; } /*read address into memory */ x = fread(&address, query.addressLength, 1, employee); if(x == FALSE) { printf("Error reading record!3\n"); return; } /*Print results */ printf("Record: %d\n", record); printf("Name: %s\n", name); printf("Address: %s\n", address); printf("Phone Number: %d\n\n", query.phoneNumber); fclose(employee); free(name); free(address); return; }
This paste will be private.
From the Design Piracy series on my blog: