diff --git a/PA02-0913/PA02_Main b/PA02-0913/PA02_Main index 1985ee8..6eadf1b 100755 Binary files a/PA02-0913/PA02_Main and b/PA02-0913/PA02_Main differ diff --git a/PA02-0913/PA02_Main.c b/PA02-0913/PA02_Main.c index e0baad7..ec390c5 100644 --- a/PA02-0913/PA02_Main.c +++ b/PA02-0913/PA02_Main.c @@ -51,7 +51,7 @@ int main() // display original list displayData( wkgArray, wkgNumStates, "Original data after upload" ); - /* + // find state printf( "\nFinding state: %s\n", searchData.name ); findStateByName( &resultData, wkgArray, wkgNumStates, searchData ); @@ -59,20 +59,20 @@ int main() resultData.population, resultData.growth * 100.00, resultData.majority ); - + // remove state printf( "\nRemoving state: %s\n", removeData.name ); removeStateByName( &resultData, wkgArray, &wkgNumStates, removeData ); - + printf( "State removed: %s, %d, %5.2f%%, %c\n", resultData.name, resultData.population, resultData.growth * 100.00, resultData.majority ); - + // display original list displayData( wkgArray, wkgNumStates, "Original data after state removal" ); - + /* // bubble sort // function: runBubbleSort runBubbleSortByName( sortingArray, sortingNumStates ); diff --git a/PA02-0913/StateUtilities.c b/PA02-0913/StateUtilities.c index 2769555..5c7af9d 100644 --- a/PA02-0913/StateUtilities.c +++ b/PA02-0913/StateUtilities.c @@ -104,9 +104,14 @@ 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) - // copy each element from the array to the new array. - // uses deepCopy to do this. + for(currentSize = 0; currentSize < srcSize; currentSize++) + { + // copy each element from the array to the new array. + // uses deepCopy to do this. + deepCopy(dest, *src); + } // no return, void } @@ -226,7 +231,7 @@ void displayData( const StateDataType *array, int size, const char *subTitle ) printCharacter(PIPE); // print new line printEndline(); - for(countStates = 0; countStates <= size; countStates++) + for(countStates = 0; countStates < size - 1; countStates++) { // use the constants to format the table // print PIPE character @@ -244,7 +249,7 @@ void displayData( const StateDataType *array, int size, const char *subTitle ) // print PIPE character printCharacter(PIPE); // print growth justified right, need a % sign too. (requires some math trickery to make work) - printDoubleJustified(array[countStates].growth, PRECISION_2, GROWTH_BLOCK_SIZE - 2, "RIGHT"); + printDoubleJustified(array[countStates].growth * 100.00, PRECISION_2, GROWTH_BLOCK_SIZE - 2, "RIGHT"); printCharacter('%'); printCharacter(SPACE); // print PIPE character @@ -281,9 +286,6 @@ void displayData( const StateDataType *array, int size, const char *subTitle ) printCharacters(MAJORITY_BLOCK_SIZE, DASH); // print PIPE character printCharacter(PIPE); - /* testing - */ - printf("Iteration: %d", countStates); // print endline printEndline(); } @@ -315,10 +317,19 @@ Dependencies: as needed bool findStateByName( StateDataType *foundElement, const StateDataType *array, int size, const StateDataType searchValue ) { + int nameCount; // iterate through array - // check to see if the state name is found (use searchValue) - // copy the element out of the array, put in foundElement - // return true + for(nameCount = 0; nameCount < size; nameCount++) + { + // check to see if the state name is found (use searchValue) + if(strcmp(array[nameCount].name, searchValue.name) == 0) + { + // copy the element out of the array, put in foundElement + deepCopy(foundElement, array[nameCount]); + // return true + return true; + } + } // otherwise, return false return false; } @@ -342,13 +353,15 @@ Dependencies: as needed bool removeStateByName( StateDataType *removedElement, StateDataType *array, int *size, const StateDataType searchVal ) { + bool stateNameFound; + stateNameFound = findStateByName(); // iterate through array // use the findStateByName to search // remove the element by copying the next element into last slot until end // reduce the size by one // return true // otherwise, return false - return NULL; + return false; } /* @@ -529,7 +542,7 @@ int uploadStateData( StateDataType *StateDataArray, readStringToDelimiterFromFile(COMMA, currentString); // find a way to cast string to double, using sscanf. sscanf(currentString, "%lf", &growthUpload); - stateUpload->growth = growthUpload * 100; + stateUpload->growth = growthUpload; // read in the majority, store readStringToDelimiterFromFile(COMMA, currentString); // get the first character of currentString diff --git a/PA02-0913/build/Debug/outDebug b/PA02-0913/build/Debug/outDebug index 1ac7c04..99ca183 100755 Binary files a/PA02-0913/build/Debug/outDebug and b/PA02-0913/build/Debug/outDebug differ