Fixed the GUR and Leverington Issues

+- PA02_Main
+- StateUtilities.c
+- outDebug (precompiled for UNIX)
This commit is contained in:
Charles Descamps 2023-09-12 16:25:56 -07:00
parent f48c96705e
commit 2cc7eca6dd
3 changed files with 39 additions and 47 deletions

Binary file not shown.

View file

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

Binary file not shown.