#include #include #include #define LINES 20 #define MAX 50 #define SZ 25 struct date { int mo, day, yr; char moabbbr[LINES]; }; struct startupcosts { float buslicense; float utilitycon; float buspermit; float startupfund; int storenumber; char storename[MAX]; struct date openingday; struct startupcosts *q; }; typedef struct roomalldata { float len, wid; char rmname[MAX]; char rmtype; int rmnumber; int stockamts[6]; float area; // sq ft float rentalrate; struct roomalldata *nextroom; } MYROOMS; typedef int fourbyte; /* functions */ int dovals(int *, int); struct date myday(struct date bday); int addstockperroom(struct roomalldata rooms[25]); int bubsort(struct roomalldata rooms[25], int s); int bubsort2(struct roomalldata rooms[25], int s); int main() { struct startupcosts mybusstart; struct date orderdate, odate; FILE *infile; fourbyte val; int i; // struct roomalldata rooms[SZ] = {0}; struct roomalldata *startroom, *currroom=NULL, *prevroom=NULL, *folroom=NULL; startroom = NULL; infile = fopen("test13datab.txt","r"); startroom = (struct roomalldata *)malloc(sizeof (struct roomalldata)); //calloc(sizeof(struct roomalldata)) fscanf(infile, "%d %d %d %d %d %d %f %f", &(startroom->stockamts[0]), &(startroom->stockamts[1]), &(startroom->stockamts[2]), &(startroom->stockamts[3]), &(startroom->stockamts[4]), &(startroom->stockamts[5]), &((*startroom).len), &(startroom->wid)); startroom->nextroom = NULL; // added the new element to the list prevroom = startroom; folroom = NULL; // printf("\nThe data in the input file is:\n"); while (!feof(infile)) { // Read data until array size is reached or // until end of file (feof(infile)) is true // Read data from a file currroom = (struct roomalldata *)malloc(sizeof (struct roomalldata)); //put data into new struct fscanf(infile, "%d %d %d %d %d %d %f %f", &(currroom->stockamts[0]), &(currroom->stockamts[1]), &(currroom->stockamts[2]), &(currroom->stockamts[3]), &(currroom->stockamts[4]), &(currroom->stockamts[5]), &(currroom->len), &(currroom->wid)); currroom->nextroom = NULL; // link new struct in order in linked list // sorting on length from smallest to largest //does new element go before beginning of list? if (currroom->len < prevroom->len) { currroom->nextroom = prevroom; startroom = currroom; prevroom = startroom; folroom = NULL; } else { while ((prevroom != NULL) && (currroom->len > prevroom->len)) { //traversing the list to find correct location folroom = prevroom; prevroom = prevroom->nextroom; } //does new element go between two elements? if (prevroom != NULL) { currroom->nextroom = prevroom; folroom->nextroom = currroom; prevroom = startroom; folroom = NULL; } //does new element go at end? else { folroom->nextroom = currroom; prevroom = startroom; folroom = NULL; } } //prevroom->nextroom = currroom; //prevroom = currroom; } // bubsort(rooms, m); //printf("\n\nAfter sort on MUSIC"); // for (i = 0; i< m; i++) currroom = startroom; printf("\nFirst struct: "); do { printf("\n%d\t %d\t %d\t %d\t %d\t %d\t %f\t %f\t %p", (currroom->stockamts[0]), (currroom->stockamts[1]), (currroom->stockamts[2]), (currroom->stockamts[3]), (currroom->stockamts[4]), (currroom->stockamts[5]), (currroom->len), currroom->wid, currroom->nextroom); currroom = currroom->nextroom; } while (currroom != NULL); return 0; } int bubsort(struct roomalldata rooms[SZ], int size) { int j,k,l,m; struct roomalldata troom; for(j=0;j rooms[k+1].stockamts[2]) { troom = rooms[k]; rooms[k] = rooms[k+1]; rooms[k+1] = troom; } else if (rooms[k].stockamts[2] == rooms[k+1].stockamts[2]) { // if MUSIC value is same, sort on room length // bubsort(&(rooms[k]),2); if (rooms[k].len > rooms[k+1].len) { troom = rooms[k]; rooms[k] = rooms[k+1]; rooms[k+1] = troom; } } } } int bubsort2(struct roomalldata rooms[SZ], int size) { int j,k,l,m; struct roomalldata troom; for(j=0;j rooms[k+1].len) { troom = rooms[k]; rooms[k] = rooms[k+1]; rooms[k+1] = troom; } } } int addstockperroom(struct roomalldata rooms[25]) { } int dovals(int *ip, int max) { } struct date myday(struct date bday) { }