diff --git a/PA02-0913/PA02_Main b/PA02-0913/PA02_Main index 1de6908..226f7e2 100755 Binary files a/PA02-0913/PA02_Main and b/PA02-0913/PA02_Main differ diff --git a/PA02-0913/StateUtilities.c b/PA02-0913/StateUtilities.c index b26c386..0ed35a7 100644 --- a/PA02-0913/StateUtilities.c +++ b/PA02-0913/StateUtilities.c @@ -9,6 +9,7 @@ const int ITEM_BLOCK_SIZE = 6; const int MAJORITY_BLOCK_SIZE = 10; const char EQUALS = '='; const char PLUS = '+'; +const int TITLE_LENGTH = 38; // functions @@ -105,7 +106,8 @@ Dependencies: as needed void copyArray( StateDataType *dest, const StateDataType *src, int srcSize ) { int currentSize; - // use a for loop to iterate through source array (start at zero, go to srcSize) + // use a for loop to iterate through source array + // (start at zero, go to srcSize) for(currentSize = 0; currentSize < srcSize; currentSize++) { // copy each element from the array to the new array. @@ -243,20 +245,25 @@ void displayData( const StateDataType *array, int size, const char *subTitle ) // print PIPE character printCharacter(PIPE); // print state name justified left - printStringJustified(array[countStates].name, NAME_BLOCK_SIZE, "LEFT"); + printStringJustified(array[countStates].name, + NAME_BLOCK_SIZE, "LEFT"); // print PIPE character printCharacter(PIPE); // print population justified right - printIntegerJustified(array[countStates].population, POPULATION_BLOCK_SIZE, "RIGHT"); + printIntegerJustified(array[countStates].population, + POPULATION_BLOCK_SIZE, "RIGHT"); // print PIPE character printCharacter(PIPE); - // print growth justified right, need a % sign too. (requires some math trickery to make work) - printDoubleJustified(array[countStates].growth * 100.00, PRECISION_2, GROWTH_BLOCK_SIZE - 2, "RIGHT"); + // print growth justified right, need a % sign too. + //(requires some math trickery to make work) + printDoubleJustified(array[countStates].growth * 100.00, + PRECISION_2, GROWTH_BLOCK_SIZE - 2, "RIGHT"); printCharacter('%'); printCharacter(SPACE); // print PIPE character printCharacter(PIPE); - // print majority justified center, also requires some math trickery to make work + // print majority justified center, + // also requires some math trickery to make work printCharacters((MAJORITY_BLOCK_SIZE - 1) / 2, SPACE); printCharacter(SPACE); printCharacter(array[countStates].majority); @@ -357,7 +364,7 @@ bool removeStateByName( StateDataType *removedElement, { bool stateNameFound; int removeCount; - int stateNameFoundFlag = 0; + bool stateNameFoundFlag = false; // use the findStateByName to search stateNameFound = findStateByName(removedElement, array, *size, searchVal); // iterate through array @@ -366,11 +373,13 @@ bool removeStateByName( StateDataType *removedElement, // for(removeCount = 0; removeCount < *size; removeCount++) { - if(strcmp(array[removeCount].name, removedElement->name) == 0 || stateNameFoundFlag == 1) + if(strcmp(array[removeCount].name, removedElement->name) == 0 || + stateNameFoundFlag == 1) { // set the flag to signify found value - stateNameFoundFlag = 1; - // remove the element by copying the next element into last slot until end + stateNameFoundFlag = true; + // remove the element by copying + // the next element into last slot until end deepCopy(&array[removeCount], array[removeCount + 1]); } } @@ -495,7 +504,7 @@ void showTitle() // print endline printEndline(); // use console io utilities to display 38 '=' - printCharacters(38, '='); + printCharacters(TITLE_LENGTH, EQUALS); // print an endline printEndline(); // no return, void @@ -515,13 +524,13 @@ Dependencies: as needed void swapElements( StateDataType *array, int leftIndex, int rightIndex ) { // create StateDataType temp to store swapped element - StateDataType *storeElement; + StateDataType storeElement; // use deepCopy to copy out swapped element - deepCopy(storeElement, array[leftIndex]); + deepCopy(&storeElement, array[leftIndex]); // use deepCopy to move the other element, deepCopy(&array[leftIndex], array[rightIndex]); // use deepCopy to copy the temp element to the other element - deepCopy(&array[rightIndex], *storeElement); + deepCopy(&array[rightIndex], storeElement); // updated the array // no return, void } @@ -544,63 +553,46 @@ Dependencies: as needed int uploadStateData( StateDataType *StateDataArray, int capacity, const char *fileName ) { - //printf("\nUploading Data?\n"); // setup a counter and other variables int stateCount = 0; - StateDataType *stateUpload; + StateDataType stateUpload; bool fileOpenCheck; char currentString[STD_STR_LEN]; - int populationUpload; - double growthUpload; - char majorityUpload; + // int populationUpload; + // double growthUpload; + // char majorityUpload; setEmptyElementData(&stateUpload); // open file fileOpenCheck = openInputFile(fileName); - //printf("\nOPENS FILE\n"); if(fileOpenCheck) { - //printf("\nCHECKED FILE\n"); - // read in the four strings/starting line (use readStringToLineEndFromFile) + // read in the four strings/starting line + // (use readStringToLineEndFromFile) readStringToLineEndFromFile(currentString); - // readStringToDelimiterFromFile(COMMA, currentString); - // readStringToDelimiterFromFile(COMMA, currentString); - // readStringToDelimiterFromFile(COMMA, currentString); - // readStringToDelimiterFromFile(COMMA, currentString); while(!checkForEndOfInputFile()) { - //printf("\nIN WHILE\n"); // repeat these steps: (use readStringToDelimiterFromFile) // read in the state name, store - //printf("\nReadingString\n"); readStringToDelimiterFromFile(COMMA, currentString); - //printf("\nReadString\n"); - //printf("\nCopy String\n"); - strcpy(stateUpload->name, currentString); - //printf("\nCopied String\n"); + strcpy(stateUpload.name, currentString); // read in the population, store (cast from string to int) - readStringToDelimiterFromFile(COMMA, currentString); - // find a way to cast string to int, sscanf might work best. - sscanf(currentString, "%d", &populationUpload); - stateUpload->population = populationUpload; + stateUpload.population = readIntegerFromFile(); + readCharacterFromFile(); // read in the growth, store (cast from string to double) - readStringToDelimiterFromFile(COMMA, currentString); - // find a way to cast string to double, using sscanf. - sscanf(currentString, "%lf", &growthUpload); - stateUpload->growth = growthUpload; + stateUpload.growth = readDoubleFromFile(); // read in the majority, store - readStringToDelimiterFromFile(COMMA, currentString); - // get the first character of currentString - majorityUpload = currentString[0]; - stateUpload->majority = majorityUpload; - // use the addElementFromData function to add the data to array - addElementFromData(StateDataArray, &stateCount, capacity, stateUpload->name, stateUpload->population, stateUpload->growth, stateUpload->majority); + readCharacterFromFile(); + stateUpload.majority = readCharacterFromFile(); + // use the addElementFromElement function to add the data to array + addElementFromElement(StateDataArray, &stateCount, + capacity, stateUpload); // do until end of the file is reached. } } else { // error out - printf("\nThe file you referenced either does not exist, or inadequate file permissions to access.\n"); + printf("\nThe file you referenced does not exist.\n"); } // return counter return stateCount; diff --git a/PA02-0913/build/Debug/outDebug b/PA02-0913/build/Debug/outDebug index bcf7d1c..0db706f 100755 Binary files a/PA02-0913/build/Debug/outDebug and b/PA02-0913/build/Debug/outDebug differ