1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
typedef struct
{ int custID;
char name[15];
char address[30];
int numBikes;
char bikeType;
char cusRisk;
} CUSTOMER;
char n1[15];
char a1[30];
int bikes1;
char biket1;
char risk1;
int id;
int i = 0;
int j;
CUSTOMER cusArray[25];
CUSTOMER *cusPtr;
double total;
system("clear");
FILE *input;
FILE *output;
input= fopen("input.txt", "r");
output= fopen("output.txt", "w");
while (true) {
fscanf( input, "%d", &id);
fscanf( input, "%[^\n]", n1);
fscanf( input, "%[^\n]", a1);
fscanf( input, "%d", &bikes1);
fscanf( input, "%c", &biket1);
fscanf( input, "%c", &risk1);
if (i < 25) {
cusArray = setfield(cusArray, i, custID, id);
cusArray = setfield(cusArray, i, name, n1);
cusArray = setfield(cusArray, i, address, a1);
cusArray = setfield(cusArray, i, numBikes, bikes1);
cusArray = setfield(cusArray, i, bikeType, biket1);
cusArray = setfield(cusArray, i, cusRisk, risk1);
}
i++;
if (i >= 25) {
break;
}
}
fclose(input);
printf("\nWhich Customer do you wish to write? (Enter ID Number)");
scanf("%d", &j);
cusPtr = cusArray + (j - 1);
fprintf("\n********** Shipping Instructions **********");
fprintf("\nTo:");
fwrite(cusPtr->custID, sizeof(int), 4, output);
fwrite(cusPtr->name, sizeof(char), 15, output);
fwrite(cusPtr->address, sizeof(char), 30, output);
if (cusPtr->bikeType == 'M') {
total += (cusPtr->numBikes * 359.95);
fwrite(cusPtr->numBikes, sizeof(int), 10, output);
}
if (cusPtr->bikeType == 'S') {
total += (cusPtr->numBikes * 279.95);
fwrite(cusPtr->numBikes, sizeof(int), 10, output);
}
if (cusPtr->cusRisk == 'N') {
fprintf("\nby freight, and bill customer %10.2f", total);
}
if (cusPtr->cusRisk == 'Y') {
fprintf("\nby freight, and COD customer %10.2f", total);
}
fprintf("\n*******************************************");
}
|