// level 3.cpp : Defines the entry point for the console application. // #include "stdafx.h" void get_field(FILE *ptr, char *name, int length); int _tmain(int argc, _TCHAR* argv[]) { char cnumber[3]; char company[34]; char ABN[12]; char street[35]; char suburb[23]; char state[6]; char postcode[8]; char phone[12]; char sale[3]; char description[44]; char part[7]; char cost[10]; char date[6]; FILE *cust_in, *sales_in; cust_in=fopen("", "r"); int i; for(i=1; i<11; i++) { // for loop.. number of customers is 10 int m = (135* i ); fseek(cust_in,m,SEEK_SET); // fseek change the file position // reads from customer file seperate array get_field(cust_in, cnumber, 3); get_field(cust_in, company, 34); get_field(cust_in, ABN, 12); get_field(cust_in, street, 35); get_field(cust_in, suburb, 23); get_field(cust_in, state, 6); get_field(cust_in, postcode, 8); get_field(cust_in, phone, 12); //display customer details printf("TOF ---------\n\n\n"); printf("ABN %s\n", ABN); printf("%s\n", company); printf("%s\n", street); printf("%s\t %s\t %s\n\n", suburb, state, postcode); printf("%s\n\n\n\n", phone); int cust_key=atoi(cnumber) ;// ascii to integer sales_in=fopen("t","r"); float total = 0; for(int k=1; k<200; k++) { //postions the cursor int u=k * 72; fseek(sales_in,u,SEEK_SET); get_field(sales_in, sale, 3); int sales_key = atoi(sale); //matching sales keys enter into array if (sales_key == cust_key) { get_field(sales_in, description, 44); get_field(sales_in, part, 7); get_field(sales_in, cost, 10); get_field(sales_in, date, 6); // sales keys matching gets entered into array float price= atof(cost); // string into a numerical representation printf("%s %s $ %1.2f %s/08/06 \n", description, part, price, date); total =+price; } fseek(sales_in,0,SEEK_SET); } printf("\t\t Total Invoice: %1.2f \n\n", total); fclose(sales_in); fseek(cust_in,0,SEEK_SET); } fclose(cust_in); return 0; } void get_field(FILE *ptr, char *name, int length) { fread(name, length, 1, ptr); name[length]='\0'; return; }