#include #include #include #define LINES 20 #define MAX 50 #define SZ 4 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; } 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; fourbyte val; struct roomalldata rooms[SZ] = {0}; MYROOMS jcroom; int bytes_read, q; int nbytes = 100; char *my_string = NULL; char arrstr[LINES][100]; FILE *infile; char t; int fi, i,j,k,m; int arri[MAX]; float ff; int *iptr; int kappa[3][5]; char *cptr; char *carrptr[10]; char **ca2ptr = &cptr; infile = fopen("test13data.txt","r"); q=0; printf("\nThe data in the input file is:\n"); for (i = 0; (i< SZ); i++) { // printf("\n\nPlease enter six stock amounts as integers and the room length and width as float"); // Read data from a file fscanf(infile, "%d %d %d %d %d %d %f %f",&(rooms[i].stockamts[0]), &(rooms[i].stockamts[1]), &(rooms[i].stockamts[2]), &(rooms[i].stockamts[3]), &(rooms[i].stockamts[4]), &(rooms[i].stockamts[5]), &(rooms[i].len), &(rooms[i].wid)); printf("\nRm[%d]\t%d\t%d\t%d\t%d\t%d\t%d\t%f\t%f",i,(rooms[i].stockamts[0]), (rooms[i].stockamts[1]), (rooms[i].stockamts[2]), (rooms[i].stockamts[3]), (rooms[i].stockamts[4]), (rooms[i].stockamts[5]), (rooms[i].len), (rooms[i].wid)); q++; } m = (q < SZ? q: SZ); bubsort(rooms, m); printf("\n\nAfter sort on MUSIC"); for (i = 0; i< m; i++) { printf("\nRm[%d]\t%d\t%d\t%d\t%d\t%d\t%d\t%f\t%f",i,(rooms[i].stockamts[0]), (rooms[i].stockamts[1]), (rooms[i].stockamts[2]), (rooms[i].stockamts[3]), (rooms[i].stockamts[4]), (rooms[i].stockamts[5]), (rooms[i].len), (rooms[i].wid)); } bubsort2(rooms, m); printf("\n"); printf("\nAfter sort2 on room length"); for (i = 0; i< m; i++) { printf("\nRm[%d]\t%d\t%d\t%d\t%d\t%d\t%d\t%f\t%f",i,(rooms[i].stockamts[0]), (rooms[i].stockamts[1]), (rooms[i].stockamts[2]), (rooms[i].stockamts[3]), (rooms[i].stockamts[4]), (rooms[i].stockamts[5]), (rooms[i].len), (rooms[i].wid)); } getc(infile); // demonstrating getline from a file and the use of strtok fi = 512; my_string = (char *)malloc(sizeof(char)*fi); getline(&my_string, &fi, infile); puts("\nString read from file is: "); puts(my_string); // using char *carrptr[10] to store pointers to words for (j = 0; j < 10; j++) carrptr[j] = NULL; // Initialize all pointers to NULL // Find the first word in the string and store in [0] pointer carrptr[0] = strtok(my_string," "); j = 1; // If the last call to strtok returned a string, keep going // Stop when the previous call to strtok returned NULL // Notice that this doesn't check array size so I could save more pointers // than I have space for in the array. while (carrptr[j-1] != NULL) { carrptr[j++] = strtok(NULL, " "); } // Print out each word that was found printf("\nThe words in the string are:\n"); for (j = 0; j < 10; j++) if (carrptr[j] != NULL) printf("String[%d] is %s \n",j,carrptr[j]); // Check to see which words start with digits and convert those to numbers printf("\nThe numbers that were in the input were: \n"); for (j = 0; j < 10; j++) if ((carrptr[j] != NULL) && (isdigit(carrptr[j][0]))) printf("String[%d] is %s, int value is %d, float val is %f \n",j,carrptr[j], atoi(carrptr[j]),atof(carrptr[j])); 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) { }