int main(int argc, char * argv[]){ //First things first. Open the input file. FILE *fp; int i = 0; if (argc != 2 || (fp = fopen(argv[1], "r")) == NULL) { printf("File open failed.\nUsage: %s <input file>\n",argv[0]); exit(1); } // initialize the symbol table, jump table and stack to 0 // method will be in instructions.c initialize(); // read the input file and prepare structures readInstructions(fp); // Close the file. fclose(fp); // Begin to interpret execute(); // debugging purposes... printTables(); printf("\nProgram halted\n"); }
int main(void){ int i, j, numRuns, itemsInRun, currentItem; int *items; // use for holding the size of all items in a run // read bins.txt and binItems.txt fpBins = fopen("bins.txt", "r"); fpBinItems = fopen("binItems.txt", "r"); fscanf(fpBinItems, "%d", &numRuns); // create a BinList structure for each algorithm ListP binList1 = createBinList(); ListP binList2 = createBinList(); ListP binList3 = createBinList(); ListP binList4 = createBinList(); ListP binList5 = createBinList(); // start packing! for (i = 0; i < numRuns; i++){ fscanf(fpBinItems, "%d", &itemsInRun); // get number of items in current run items = malloc(sizeof(int) * itemsInRun); for (j = 0; j < itemsInRun; j++){ fscanf(fpBinItems, "%d", ¤tItem); items[j] = currentItem; } // perform all 5 algorithms OnlineFirstFit(binList1, items, itemsInRun); OnlineNextFit(binList2, items, itemsInRun); OnlineBestFit(binList3, items, itemsInRun); OfflineFirstFit(binList4, items, itemsInRun); OfflineBestFit(binList5, items, itemsInRun); // print results printf("Run %d\n", i+1); printTables(binList1, binList2, binList3, binList4, binList5); // reset all binLists and data binList1 = resetBinList(binList1); binList2 = resetBinList(binList2); binList3 = resetBinList(binList3); binList4 = resetBinList(binList4); binList5 = resetBinList(binList5); free(items); } // free all BinLists and close files binList1 = freeBinList(binList1); binList2 = freeBinList(binList2); binList3 = freeBinList(binList3); binList4 = freeBinList(binList4); binList5 = freeBinList(binList5); fclose(fpBinItems); fclose(fpBins); getchar(); return 0; }