From b80e8624c04f6c924617c6d480ee242fb25db8e5 Mon Sep 17 00:00:00 2001 From: cdez Date: Sat, 2 Sep 2023 13:47:45 -0700 Subject: [PATCH 01/10] Aded MakefilIes and Template ++ MakefilIe --- PA01-0906/Makefile | 32 ++++++++++++++++++++++++++++++++ TypicalUtils/Makefile | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 PA01-0906/Makefile create mode 100644 TypicalUtils/Makefile diff --git a/PA01-0906/Makefile b/PA01-0906/Makefile new file mode 100644 index 0000000..654ac86 --- /dev/null +++ b/PA01-0906/Makefile @@ -0,0 +1,32 @@ +CC = gcc -Wall +SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c +OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o + +all: PA01_Main.out + +PA01_Main.out: PA01_Main + ./PA01_Main | tee PA01_Main.out + +PA01_Main: $(OBJECTS) + $(CC) $(OBJECTS) -o PA01_Main + +PA01_Main.o: PA01_Main.c + $(CC) -c PA01_Main.c -o PA01_Main.o + +EncryptionUtility.o: EncryptionUtility.c + $(CC) -c EncryptionUtility.c -o EncryptionUtility.o + +Console_IO_Utility.o: Console_IO_Utility.c + $(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o + +File_Input_Utility.o: File_Input_Utility.c + $(CC) -c File_Input_Utility.c -o File_Input_Utility.o + +File_Output_Utility.o: File_Output_Utility.c + $(CC) -c File_Output_Utility.c -o File_Output_Utility.o + +clean: + rm -f $(OBJECTS) PA01_Main PA01_Main.out + +clean_objects: + rm -f $(OBJECTS) diff --git a/TypicalUtils/Makefile b/TypicalUtils/Makefile new file mode 100644 index 0000000..3be447c --- /dev/null +++ b/TypicalUtils/Makefile @@ -0,0 +1,20 @@ +CC = gcc -Wall +SOURCES = main.c get_student_id.c +OBJECTS = main.o get_student_id.o + +all: main.out + +main.out: main + ./main | tee main.out + +main: $(OBJECTS) + $(CC) $(OBJECTS) -o main + +main.o: main.c + $(CC) -c main.c -o main.o + +get_student_id.o: get_student_id.c + $(CC) -c get_student_id.c -o get_student_id.o + +clean: + rm -f $(OBJECTS) main main.out From 40e0bfd79a6cd12e7ddaceba8f2c3c3a46e4b9de Mon Sep 17 00:00:00 2001 From: cdez Date: Sun, 3 Sep 2023 14:45:51 -0700 Subject: [PATCH 02/10] Modified PA01 Files +- EncryptionUtility.c +- PA01_Main.c --- PA01-0906/EncryptionUtility.c | 99 ++++++++++++++++++++++++++++++++-- PA01-0906/PA01_Main | Bin 0 -> 24632 bytes PA01-0906/PA01_Main.c | 17 +++++- 3 files changed, 110 insertions(+), 6 deletions(-) create mode 100755 PA01-0906/PA01_Main diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 34811a2..74ff263 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -117,6 +117,9 @@ Dependencies: as needed, File_Output_Utility tools */ void downloadData( const char *fileName, const SquareArrayType data ) { + // open file. + // write file. + // close file. // no return. } @@ -135,6 +138,41 @@ Dependencies: as needed, including findStringLength, findSquareRoot, */ SquareArrayType *encryptData( const char *toEncrypt ) { + // get length of string (store in variable) + int stringLen = findStringLength(toEncrypt); + // create the array (get the square root, add one, then call the function to make a square array.) + int stringLenRoot = findSquareRoot(stringLen) + 1; + SquareArrayType *encryptedData = createArrayType(stringLenRoot); + // iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array] + int oneDimensionIndex; + int twoDimensionIndex; + int currentCharacter = 0; + int flagEndString = 0; + for(oneDimensionIndex = stringLenRoot; oneDimensionIndex >= 0; oneDimensionIndex--) + { + // one dimension to move through array + for(twoDimensionIndex = stringLenRoot; twoDimensionIndex >= 0; twoDimensionIndex--) + { + // second dimension to move through array + if(toEncrypt[currentCharacter] == NULL_CHAR) + { + // if the null character is there, replace with the Unprintable, set flag to one. + encryptedData[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; + flagEndString = 1; + } + else + { + // otherwise, continue putting the data into the 2d array. + encryptedData[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; + } + if(flagEndString == 1) + { + // check the flag, if it is set, then start putting random data into rest of the array. + encryptedData[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); + } + } + } + // once null character is reached, put the 'unprintable character' then random data afterward. // returns a Square Array. return NULL; } @@ -152,8 +190,47 @@ Dependencies: as needed (library utilities may not be used) */ double findSquareRoot( int value ) { - // returns a double. - return 0.0; + // declare, define variables as needed + + // set lower value to zero, upper value to the original value + double lowerValue = 0, upperValue = value; + + // set middle value between the lower and upper values + double middleValue = ( lowerValue + upperValue ) / 2.0; + + // calculate the initial temporary value + double tempResult = middleValue * middleValue; + + // loop while absolute difference between test value and original value + // is greater than the specified precision + // function: abs, from stdlib.h + while( abs( tempResult - value ) > SQRT_PRECISION ) + { + // test for the temporary result to be greater than the original value + if( tempResult > value ) + { + // set the upper value to the middle value + upperValue = middleValue; + } + + // otherwise, assume the temporary result is less than the original value + else + { + // set the lower value to the middle value + lowerValue = middleValue; + } + // end test + + // recalculate middle value + middleValue = ( lowerValue + upperValue ) / 2.0; + + // recalculate the temporary result + tempResult = middleValue * middleValue; + } + // end loop + + // return middle value + return middleValue; } /* @@ -168,8 +245,15 @@ Dependencies: as needed (library utilities may not be used) */ int findStringLength( const char *str ) { - // returns an integer. - return 0; + // needs to iterate through the 'string' checking if the character is NULL. + // if character not null, add one to count. + int index = 0; + while(str[index] != NULL_CHAR) + { + index = index + 1; + } + // returns an integer count of the number of characters. + return index; } /* @@ -185,8 +269,13 @@ Dependencies: as needed, including rand */ int getRandomLetterValue() { + int currentRand = 0; + // generate random number between 1 and 52 + currentRand = rand() % (NUM_ALPHABET_LETTERS + 1) + 1; + // then get the integer that character corresponds to and return it. + int letterInt = (int)ALPHABET[currentRand]; // returns an integer. - return 0; + return letterInt; } /* diff --git a/PA01-0906/PA01_Main b/PA01-0906/PA01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nhJuPuV$;V?h2IH+z5T5$uVD4xX#eM$d@tWDP;esOPte;}^+z>% zb$?sIGZZ63J$_HHyy|~-pH4x)MUV>ItVe<0;DTIKZ0h-sf)f;h1@!j+pvkYDD;X7> zs|F0qYgO@m)^VWG9HgS&Gf>~T*7;Rk!8ag7_qvt5dJn<9khG=8tE{E#O8x^7XzVI^ z^;}GSw|tQMpXMJGC8x&E4}l{VC9mE?m~<6!<2_ditiMWL!BZe?m$&W*mq-!Sj#8lH zRDCRj38&gu_kRjXBu9~AWT?xJ=k|3zCC|5AEG=X!6+6_1h@h902w)uG0Zg~!&&N-- ruktT$<5;#!3Hf*QG6`#m!B$ke3PsaZ`L1vTZ={6 Date: Mon, 4 Sep 2023 13:52:30 -0700 Subject: [PATCH 03/10] Uploading Changes +- EncryptionUtility.c +- PA01_Main --- PA01-0906/EncryptionUtility.c | 50 +++++++++++++++++++++++++++------- PA01-0906/PA01_Main | Bin 24632 -> 24656 bytes PA01-0906/PA01_Main.c | 31 ++++++++++----------- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 74ff263..8d5281a 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -101,6 +101,35 @@ Notes: Does not handle empty square data type condition */ void displayArray( const SquareArrayType data, ControlCode ctrlCode ) { + int arraySize = data.sideSize; + int oneDimensionIndex = 0, twoDimensionIndex = 0; + // check the control code, branch to the respective path. + // iterate through the array, one character at a time. + // get the side size from the array, iterate that number of times, then output a new line. + if(ctrlCode == DISPLAY_CHARS) + { + for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++) + { + for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++) + { + printCharacter((char)data.array[oneDimensionIndex][twoDimensionIndex]); + printCharacter(SPACE); + } + printEndline(); + } + } + else + { + for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++) + { + for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++) + { + printInteger((int)data.array[oneDimensionIndex][twoDimensionIndex]); + printCharacter(SPACE); + } + printEndline(); + } + } // no return. } /* @@ -148,33 +177,34 @@ SquareArrayType *encryptData( const char *toEncrypt ) int twoDimensionIndex; int currentCharacter = 0; int flagEndString = 0; - for(oneDimensionIndex = stringLenRoot; oneDimensionIndex >= 0; oneDimensionIndex--) + for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--) { // one dimension to move through array - for(twoDimensionIndex = stringLenRoot; twoDimensionIndex >= 0; twoDimensionIndex--) + for(twoDimensionIndex = stringLenRoot - 1; twoDimensionIndex >= 0; twoDimensionIndex--) { + if(flagEndString == 1) + { + // check the flag, if it is set, then start putting random data into rest of the array. + encryptedData->array[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); + } // second dimension to move through array if(toEncrypt[currentCharacter] == NULL_CHAR) { // if the null character is there, replace with the Unprintable, set flag to one. - encryptedData[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; + encryptedData->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; flagEndString = 1; } else { // otherwise, continue putting the data into the 2d array. - encryptedData[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; - } - if(flagEndString == 1) - { - // check the flag, if it is set, then start putting random data into rest of the array. - encryptedData[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); + encryptedData->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; } + currentCharacter = currentCharacter + 1; } } // once null character is reached, put the 'unprintable character' then random data afterward. // returns a Square Array. - return NULL; + return encryptedData; } /* diff --git a/PA01-0906/PA01_Main b/PA01-0906/PA01_Main index b130d3b178c2c9a9e95b63c3d4a2e006bd4fe0bb..286b1005fff1b1ad6175bce1d59d609867121c56 100755 GIT binary patch delta 7657 zcmai34OCP|mVWO63fS1)s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++++++++++++++--------- PA01-0906/PA01_Main | Bin 24656 -> 24656 bytes 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 8d5281a..c16aa9e 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -21,11 +21,11 @@ Dependencies: as needed */ SquareArrayType *clearArrayType( SquareArrayType *data ) { - int rowIndex; + int oneDimensionIndex; - for( rowIndex = 0; rowIndex < data->sideSize; rowIndex++ ) + for( oneDimensionIndex = 0; oneDimensionIndex < data->sideSize; oneDimensionIndex++ ) { - free( data->array[ rowIndex ] ); + free( data->array[ oneDimensionIndex ] ); } free( data->array ); @@ -50,7 +50,7 @@ Dependencies: as needed */ SquareArrayType *createArrayType( int sideSize ) { - int rowIndex, colIndex; + int oneDimensionIndex, twoDimensionIndex; SquareArrayType *newData; newData = (SquareArrayType *)malloc( sizeof( SquareArrayType ) ); @@ -59,13 +59,13 @@ SquareArrayType *createArrayType( int sideSize ) newData->array = (int **)malloc( sideSize * sizeof( int * ) ); - for( rowIndex = 0; rowIndex < sideSize; rowIndex++ ) + for( oneDimensionIndex = 0; oneDimensionIndex < sideSize; oneDimensionIndex++ ) { - newData->array[ rowIndex ] = (int *)malloc( sideSize * sizeof( int ) ); + newData->array[ oneDimensionIndex ] = (int *)malloc( sideSize * sizeof( int ) ); - for( colIndex = 0; colIndex < sideSize; colIndex++ ) + for( twoDimensionIndex = 0; twoDimensionIndex < sideSize; twoDimensionIndex++ ) { - newData->array[ rowIndex ][ colIndex ] = (int)ASTERISK; + newData->array[ oneDimensionIndex ][ twoDimensionIndex ] = (int)ASTERISK; } } @@ -175,33 +175,67 @@ SquareArrayType *encryptData( const char *toEncrypt ) // iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array] int oneDimensionIndex; int twoDimensionIndex; + int differenceIndex; int currentCharacter = 0; int flagEndString = 0; - for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--) + // for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--) + // { + // // one dimension to move through array + // for(twoDimensionIndex = stringLenRoot - 1; twoDimensionIndex >= 0; twoDimensionIndex--) + // { + // if(flagEndString == 1) + // { + // // check the flag, if it is set, then start putting random data into rest of the array. + // encryptedData->array[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); + // } + // // second dimension to move through array + // if(toEncrypt[currentCharacter] == NULL_CHAR) + // { + // // if the null character is there, replace with the Unprintable, set flag to one. + // encryptedData->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; + // flagEndString = 1; + // } + // else + // { + // // otherwise, continue putting the data into the 2d array. + // encryptedData->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; + // } + // currentCharacter = currentCharacter + 1; + // } + // } +for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--) +{ + // + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) { - // one dimension to move through array - for(twoDimensionIndex = stringLenRoot - 1; twoDimensionIndex >= 0; twoDimensionIndex--) + // + differenceIndex = oneDimensionIndex - twoDimensionIndex; + if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot) { - if(flagEndString == 1) - { - // check the flag, if it is set, then start putting random data into rest of the array. - encryptedData->array[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); - } + // printf("C "); // second dimension to move through array if(toEncrypt[currentCharacter] == NULL_CHAR) { // if the null character is there, replace with the Unprintable, set flag to one. - encryptedData->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; + encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE; + currentCharacter = currentCharacter + 1; flagEndString = 1; } else { // otherwise, continue putting the data into the 2d array. - encryptedData->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; + encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter]; + } + if(flagEndString == 1) + { + // check the flag, if it is set, then start putting random data into rest of the array. + encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue(); } currentCharacter = currentCharacter + 1; } } + //printf("\n"); +} // once null character is reached, put the 'unprintable character' then random data afterward. // returns a Square Array. return encryptedData; diff --git a/PA01-0906/PA01_Main b/PA01-0906/PA01_Main index 286b1005fff1b1ad6175bce1d59d609867121c56..70ca7c01756fab69b2512958ddebba3e261687ff 100755 GIT binary patch delta 3408 zcmZ{mdr(tX9>?#wfP$hS_y{QpmjH=8LPC6?fLg6wxIF5vR$SfMmA2O6hz}}u?T#*1 z)G-Zg3%~8m)?I6zc74oJM?_g2I|b27Z8J6~-8$8^Y^53{u7J2wMYG?VTqQWu{PFvo z^Lw4w@0?s$GjlbwL!m5ehQRrLGaA(Fb$;v*DQ8>1%3YQp{A^Xjy{X1awfi0%YN!fw zMyNZ&IZmqH*8RxqmF%tVu%Lz&V^#c^m91i@oSVS z$dE)IQ@SR-LXzy8j!6#jm^|SOp5yG|WruhfoovQ&y{d>&Z)jyMI@zl-H`~Pyhu8t* zClBQ%itbjiU7lpCcu@vy3_i{qeZG#hvPVQ%&yhuAK?3J*-4xm1nZ*5>sS ze=!9OXrkv2@eln)Uu8JfqWb)#ov#$zS>-AhtK8(`RQ71E*IT*DiJlWZo_0pf;73G} zMXROWs7!X0Qnho~TU4f9#$WEI@3eaMDc#jh)r9nWy>_v`RUE)_xvua^ae%qI@6nuR z2Ke6p(d_7A-gTEgj^4obl1`U3Zs%CJmZrQf!`|v&wuwr0u`GnDbxGq!-t~IVp1Pxo zxnCsNe`*?mr0#w6wa(5~QIURf;y%+&4`WTEyHo)q?;)FETIdD~ z$Eg}a%Baj>41EC|$q`aW9~!2xVbpGzI_BDK-zIdad}V~ie|wu^;xgIWv^dVl;;ABT zGkc>pelA-_zltwr$#f|GG<%KKCm140ekTIX=8}i@ClrL8^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svvkoPwiffww1x^1}nyLtFG=`fr{i%3bP*QAS7S$Z+HVi-4 z%-gA@#Lf=U{*&V8V8qB=uAqL?0AQkNF{i~_Dak7Q;Ecv zX5y7`l$JPF7*+qki;7_c+CmBI)JjRx(wQ~=PWq_yc!;h+QflwM}nJLa2Po%jCfm0E9|CU#;cisqfIa!y{JsUk-Nf Date: Mon, 4 Sep 2023 22:46:06 -0700 Subject: [PATCH 05/10] Finished PA01 +- EncryptionUtility.c +- PA01_Main.c --- PA01-0906/EncryptionUtility.c | 188 ++++++++++++++++++++++++---------- PA01-0906/PA01_Main.c | 7 +- 2 files changed, 138 insertions(+), 57 deletions(-) diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index c16aa9e..253cfc0 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -84,6 +84,45 @@ Dependencies: as needed */ void decryptData( char *decryptStr, SquareArrayType *data ) { + // opposite the encrypt data. + // extract the size data from the array + int arraySizeData = data->sideSize; + // iterate through the array + int oneDimensionIndex; + int twoDimensionIndex; + int differenceIndex; + int currentCharacter = 0; + int stringComplete = 0; + for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0; oneDimensionIndex--) + { + // does one dimensional indices + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) + { + // does two dimensional indices + differenceIndex = oneDimensionIndex - twoDimensionIndex; + if(differenceIndex < arraySizeData && twoDimensionIndex < arraySizeData) + { + // printf("C "); + // second dimension to move through array + if(stringComplete == 0) + { + if(data->array[twoDimensionIndex][differenceIndex] == UNPRINTABLE_CHAR_VALUE) + { + // check for the unprintable character + decryptStr[currentCharacter] = NULL_CHAR; + stringComplete = 1; + } + else + { + // put the character into the string. + decryptStr[currentCharacter] = data->array[twoDimensionIndex][differenceIndex]; + currentCharacter = currentCharacter + 1; + } + } + } + } + // printf("\n"); + } // no return. } @@ -146,9 +185,51 @@ Dependencies: as needed, File_Output_Utility tools */ void downloadData( const char *fileName, const SquareArrayType data ) { + bool fileOpenCheck; + int oneDimensionIndex, twoDimensionIndex; + int currentData; + int checkDigits, tempDigits; // open file. + fileOpenCheck = openOutputFile(fileName); // write file. + if(fileOpenCheck) + { + // write the size of the array as the first character. + writeIntegerToFile(data.sideSize); + // write a new line + writeEndlineToFile(); + // iterate through array outputting each integer. + for(oneDimensionIndex = 0; oneDimensionIndex < data.sideSize; oneDimensionIndex++) + { + // + for(twoDimensionIndex = 0; twoDimensionIndex < data.sideSize; twoDimensionIndex++) + { + // + currentData = data.array[oneDimensionIndex][twoDimensionIndex]; + // check to see if the integer is two digits, if it is, add a 0 before. + checkDigits = 1; + tempDigits = currentData; + while(tempDigits > 9) + { + tempDigits = tempDigits / 10; + checkDigits = checkDigits + 1; + } + if(checkDigits == 2) + { + writeCharacterToFile(ZERO_CHAR); + writeIntegerToFile(currentData); + } + else + { + writeIntegerToFile(currentData); + } + writeCharacterToFile(SPACE); + } + writeEndlineToFile(); + } + } // close file. + closeOutputFile(); // no return. } @@ -177,65 +258,40 @@ SquareArrayType *encryptData( const char *toEncrypt ) int twoDimensionIndex; int differenceIndex; int currentCharacter = 0; - int flagEndString = 0; - // for(oneDimensionIndex = stringLenRoot - 1; oneDimensionIndex >= 0; oneDimensionIndex--) - // { - // // one dimension to move through array - // for(twoDimensionIndex = stringLenRoot - 1; twoDimensionIndex >= 0; twoDimensionIndex--) - // { - // if(flagEndString == 1) - // { - // // check the flag, if it is set, then start putting random data into rest of the array. - // encryptedData->array[oneDimensionIndex][twoDimensionIndex] = getRandomLetterValue(); - // } - // // second dimension to move through array - // if(toEncrypt[currentCharacter] == NULL_CHAR) - // { - // // if the null character is there, replace with the Unprintable, set flag to one. - // encryptedData->array[oneDimensionIndex][twoDimensionIndex] = UNPRINTABLE_CHAR_VALUE; - // flagEndString = 1; - // } - // else - // { - // // otherwise, continue putting the data into the 2d array. - // encryptedData->array[oneDimensionIndex][twoDimensionIndex] = toEncrypt[currentCharacter]; - // } - // currentCharacter = currentCharacter + 1; - // } - // } -for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--) -{ - // - for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) + for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--) { - // - differenceIndex = oneDimensionIndex - twoDimensionIndex; - if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot) + // does one dimensional indices + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) { - // printf("C "); - // second dimension to move through array - if(toEncrypt[currentCharacter] == NULL_CHAR) + // does two dimensional indices + differenceIndex = oneDimensionIndex - twoDimensionIndex; + if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot) { - // if the null character is there, replace with the Unprintable, set flag to one. - encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE; + // printf("C "); + // second dimension to move through array + if(currentCharacter >= stringLen) + { + if(currentCharacter == stringLen) + { + // if the null character is there, replace with the Unprintable, set flag to one. + encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE; + } + else + { + // if not the null, put random data into array + encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue(); + } + } + else + { + // otherwise, continue putting the data into the 2d array. + encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter]; + } currentCharacter = currentCharacter + 1; - flagEndString = 1; } - else - { - // otherwise, continue putting the data into the 2d array. - encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter]; - } - if(flagEndString == 1) - { - // check the flag, if it is set, then start putting random data into rest of the array. - encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue(); - } - currentCharacter = currentCharacter + 1; } + //printf("\n"); } - //printf("\n"); -} // once null character is reached, put the 'unprintable character' then random data afterward. // returns a Square Array. return encryptedData; @@ -355,6 +411,32 @@ Dependencies: as needed, File_Input_Utility tools */ SquareArrayType *uploadData( const char *fileName ) { + bool fileOpenCheck; + int arraySizeFile; + int oneDimensionIndex, twoDimensionIndex; + SquareArrayType *readArray; + // open file. + fileOpenCheck = openInputFile(fileName); + // read file. + if(fileOpenCheck) + { + // read the size of the array as the first character. + arraySizeFile = readIntegerFromFile(); + // create the square array + readArray = createArrayType(arraySizeFile); + // read integer, iterate through array inputting each integer. + for(oneDimensionIndex = 0; oneDimensionIndex < arraySizeFile; oneDimensionIndex++) + { + // + for(twoDimensionIndex = 0; twoDimensionIndex < arraySizeFile; twoDimensionIndex++) + { + // + readArray->array[oneDimensionIndex][twoDimensionIndex] = readIntegerFromFile(); + } + } + } + // close file. + closeInputFile(); // returns a Square Array. - return NULL; + return readArray; } diff --git a/PA01-0906/PA01_Main.c b/PA01-0906/PA01_Main.c index 7b33ebb..9cd688f 100644 --- a/PA01-0906/PA01_Main.c +++ b/PA01-0906/PA01_Main.c @@ -43,12 +43,12 @@ int main( int argc, char *args[] ) printf( "\nDisplay encryption as characters:\n" ); displayArray( *encryptedInput, DISPLAY_CHARS ); - /* + printf( "\nDecrypting the input string\n" ); decryptData( decryptedStr, encryptedInput ); printf( "\nDecrypted string: %s\n", decryptedStr ); - + printf( "\nDownloading encryption\n" ); promptForString( "\nEnter file name for download: ", fileName ); downloadData( fileName, *encryptedInput ); @@ -64,12 +64,11 @@ int main( int argc, char *args[] ) decryptData( stringFromFile, uploadedInput ); printf( "\nUploaded string: %s\n", stringFromFile ); - */ // end program // clear arrays - // encryptedInput = clearArrayType( encryptedInput ); + encryptedInput = clearArrayType( encryptedInput ); // display end of program printf( "\nProgram End\n" ); From c7bcb36a7671f58453c7ab2bdd82113af92cf9e3 Mon Sep 17 00:00:00 2001 From: cdez Date: Mon, 4 Sep 2023 23:20:38 -0700 Subject: [PATCH 06/10] Release Ready! +- Makefile for compiling +- EncryptionUtility.c (80 char limits) ++ outRelease (precompiled program for UNIX systems) --- PA01-0906/EncryptionUtility.c | 91 +++++++++++++++++------------ PA01-0906/Makefile | 8 +-- PA01-0906/PA01_Main | Bin 24656 -> 28752 bytes PA01-0906/build/Release/outRelease | Bin 0 -> 36848 bytes 4 files changed, 58 insertions(+), 41 deletions(-) create mode 100755 PA01-0906/build/Release/outRelease diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 253cfc0..5b5bfef 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -21,11 +21,11 @@ Dependencies: as needed */ SquareArrayType *clearArrayType( SquareArrayType *data ) { - int oneDimensionIndex; + int rowIndex; - for( oneDimensionIndex = 0; oneDimensionIndex < data->sideSize; oneDimensionIndex++ ) + for( rowIndex = 0; rowIndex < data->sideSize; rowIndex++ ) { - free( data->array[ oneDimensionIndex ] ); + free( data->array[ rowIndex ] ); } free( data->array ); @@ -50,7 +50,7 @@ Dependencies: as needed */ SquareArrayType *createArrayType( int sideSize ) { - int oneDimensionIndex, twoDimensionIndex; + int rowIndex, colIndex; SquareArrayType *newData; newData = (SquareArrayType *)malloc( sizeof( SquareArrayType ) ); @@ -59,13 +59,13 @@ SquareArrayType *createArrayType( int sideSize ) newData->array = (int **)malloc( sideSize * sizeof( int * ) ); - for( oneDimensionIndex = 0; oneDimensionIndex < sideSize; oneDimensionIndex++ ) + for( rowIndex = 0; rowIndex < sideSize; rowIndex++ ) { - newData->array[ oneDimensionIndex ] = (int *)malloc( sideSize * sizeof( int ) ); + newData->array[ rowIndex ] = (int *)malloc( sideSize * sizeof( int ) ); - for( twoDimensionIndex = 0; twoDimensionIndex < sideSize; twoDimensionIndex++ ) + for( colIndex = 0; colIndex < sideSize; colIndex++ ) { - newData->array[ oneDimensionIndex ][ twoDimensionIndex ] = (int)ASTERISK; + newData->array[ rowIndex ][ colIndex ] = (int)ASTERISK; } } @@ -93,20 +93,22 @@ void decryptData( char *decryptStr, SquareArrayType *data ) int differenceIndex; int currentCharacter = 0; int stringComplete = 0; - for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0; oneDimensionIndex--) + for(oneDimensionIndex = arraySizeData * 2; oneDimensionIndex >= 0; + oneDimensionIndex--) { // does one dimensional indices - for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; + twoDimensionIndex--) { // does two dimensional indices differenceIndex = oneDimensionIndex - twoDimensionIndex; if(differenceIndex < arraySizeData && twoDimensionIndex < arraySizeData) { - // printf("C "); // second dimension to move through array if(stringComplete == 0) { - if(data->array[twoDimensionIndex][differenceIndex] == UNPRINTABLE_CHAR_VALUE) + if(data->array[twoDimensionIndex][differenceIndex] == + UNPRINTABLE_CHAR_VALUE) { // check for the unprintable character decryptStr[currentCharacter] = NULL_CHAR; @@ -115,13 +117,13 @@ void decryptData( char *decryptStr, SquareArrayType *data ) else { // put the character into the string. - decryptStr[currentCharacter] = data->array[twoDimensionIndex][differenceIndex]; + decryptStr[currentCharacter] = + data->array[twoDimensionIndex][differenceIndex]; currentCharacter = currentCharacter + 1; } } } } - // printf("\n"); } // no return. } @@ -144,12 +146,15 @@ void displayArray( const SquareArrayType data, ControlCode ctrlCode ) int oneDimensionIndex = 0, twoDimensionIndex = 0; // check the control code, branch to the respective path. // iterate through the array, one character at a time. - // get the side size from the array, iterate that number of times, then output a new line. + // get the side size from the array, + // iterate that number of times, then output a new line. if(ctrlCode == DISPLAY_CHARS) { - for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++) + for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; + oneDimensionIndex++) { - for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++) + for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; + twoDimensionIndex++) { printCharacter((char)data.array[oneDimensionIndex][twoDimensionIndex]); printCharacter(SPACE); @@ -159,9 +164,11 @@ void displayArray( const SquareArrayType data, ControlCode ctrlCode ) } else { - for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; oneDimensionIndex++) + for(oneDimensionIndex = 0; oneDimensionIndex < arraySize; + oneDimensionIndex++) { - for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; twoDimensionIndex++) + for(twoDimensionIndex = 0; twoDimensionIndex < arraySize; + twoDimensionIndex++) { printInteger((int)data.array[oneDimensionIndex][twoDimensionIndex]); printCharacter(SPACE); @@ -199,10 +206,12 @@ void downloadData( const char *fileName, const SquareArrayType data ) // write a new line writeEndlineToFile(); // iterate through array outputting each integer. - for(oneDimensionIndex = 0; oneDimensionIndex < data.sideSize; oneDimensionIndex++) + for(oneDimensionIndex = 0; oneDimensionIndex < data.sideSize; + oneDimensionIndex++) { // - for(twoDimensionIndex = 0; twoDimensionIndex < data.sideSize; twoDimensionIndex++) + for(twoDimensionIndex = 0; twoDimensionIndex < data.sideSize; + twoDimensionIndex++) { // currentData = data.array[oneDimensionIndex][twoDimensionIndex]; @@ -250,49 +259,55 @@ SquareArrayType *encryptData( const char *toEncrypt ) { // get length of string (store in variable) int stringLen = findStringLength(toEncrypt); - // create the array (get the square root, add one, then call the function to make a square array.) + // create the array (get the square root, add one, + // then call the function to make a square array.) int stringLenRoot = findSquareRoot(stringLen) + 1; SquareArrayType *encryptedData = createArrayType(stringLenRoot); - // iterate through the array (backwards?) [Past Charles, see diagram that you made of Square Array] + // iterate through the array (backwards, diagonally) int oneDimensionIndex; int twoDimensionIndex; int differenceIndex; int currentCharacter = 0; - for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; oneDimensionIndex--) + for(oneDimensionIndex = stringLenRoot * 2; oneDimensionIndex >= 0; + oneDimensionIndex--) { // does one dimensional indices - for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; twoDimensionIndex--) + for(twoDimensionIndex = oneDimensionIndex; twoDimensionIndex >= 0; + twoDimensionIndex--) { // does two dimensional indices differenceIndex = oneDimensionIndex - twoDimensionIndex; if(differenceIndex < stringLenRoot && twoDimensionIndex < stringLenRoot) { - // printf("C "); // second dimension to move through array if(currentCharacter >= stringLen) { if(currentCharacter == stringLen) { - // if the null character is there, replace with the Unprintable, set flag to one. - encryptedData->array[twoDimensionIndex][differenceIndex] = UNPRINTABLE_CHAR_VALUE; + // if the null character is there, + // replace with the Unprintable, set flag to one. + encryptedData->array[twoDimensionIndex][differenceIndex] = + UNPRINTABLE_CHAR_VALUE; } else { // if not the null, put random data into array - encryptedData->array[twoDimensionIndex][differenceIndex] = getRandomLetterValue(); + encryptedData->array[twoDimensionIndex][differenceIndex] = + getRandomLetterValue(); } } else { // otherwise, continue putting the data into the 2d array. - encryptedData->array[twoDimensionIndex][differenceIndex] = toEncrypt[currentCharacter]; + encryptedData->array[twoDimensionIndex][differenceIndex] = + toEncrypt[currentCharacter]; } currentCharacter = currentCharacter + 1; } } - //printf("\n"); } - // once null character is reached, put the 'unprintable character' then random data afterward. + // once null character is reached, put the 'unprintable character' + // then random data afterward. // returns a Square Array. return encryptedData; } @@ -425,13 +440,15 @@ SquareArrayType *uploadData( const char *fileName ) // create the square array readArray = createArrayType(arraySizeFile); // read integer, iterate through array inputting each integer. - for(oneDimensionIndex = 0; oneDimensionIndex < arraySizeFile; oneDimensionIndex++) + for(oneDimensionIndex = 0; oneDimensionIndex < arraySizeFile; + oneDimensionIndex++) { - // - for(twoDimensionIndex = 0; twoDimensionIndex < arraySizeFile; twoDimensionIndex++) + for(twoDimensionIndex = 0; twoDimensionIndex < arraySizeFile; + twoDimensionIndex++) { - // - readArray->array[oneDimensionIndex][twoDimensionIndex] = readIntegerFromFile(); + // input data into array from file + readArray->array[oneDimensionIndex][twoDimensionIndex] = + readIntegerFromFile(); } } } diff --git a/PA01-0906/Makefile b/PA01-0906/Makefile index 654ac86..b806f02 100644 --- a/PA01-0906/Makefile +++ b/PA01-0906/Makefile @@ -2,10 +2,7 @@ CC = gcc -Wall SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o -all: PA01_Main.out - -PA01_Main.out: PA01_Main - ./PA01_Main | tee PA01_Main.out +all: PA01_Main PA01_Main: $(OBJECTS) $(CC) $(OBJECTS) -o PA01_Main @@ -30,3 +27,6 @@ clean: clean_objects: rm -f $(OBJECTS) + +run: + ./PA01_Main \ No newline at end of file diff --git a/PA01-0906/PA01_Main b/PA01-0906/PA01_Main index 70ca7c01756fab69b2512958ddebba3e261687ff..73d212aea64236965c46fe36a082efb299a5c736 100755 GIT binary patch delta 9612 zcma)C4Ompwy56$^1wi%@UlDQ?wvC30b?l@(Xe~ z3zT^l=gsATQVQYyJTA$LrkMUh)gn|acMN!(0pDl9XACqDEe2wc z0Y7fQ;|;jWfG0GY`e>n~MGoC;j!K>*N%jpb^|I!&H+&p^gxP50uFaODYg+pC+08lT z19%dy-5t4a`17}OsZ)E^PlPY>!3 z4eG}Q_4@|)7pI2>0_i`M1ZLpJp#GJh{>7mFH$nZcO33Y))DbTXl_V{$8RU%`YjpDS zY&Gmng=c`+o5H@NVp4Z~oZT6=rG(gHhlDd?+-oJIHg<@qgg9c8vH(eIa^~3^3a8Pg z-Epx#%I++jj*k12pES)~rD@vHu)-4JicPgNcr1?Yjf%&;>Ss-JDBZ^tFCDcrszLFZ z++{zLXA->f!#|O=iIsAJmz+y{LXPp0lR5bV&t}n}#(hPF>PIOnLilsx##_$w?k%^LEqVy>_S4YHx}gz${L~tNVf5nzo^3 zO&_OnAxH6Iex3IVr5hR4EmN}ICfk#L8@+`gVkS>?6WL;oo^Qk^catfWd+bq0?CLE| zvo|SScE?ey(2aCMG8z!nwP>@_Rb!8Srp4}@*Ii}L8IX=COZ8#yH*S%<^f+?XGBkU$ z(W;(1yulq-8>xtHl9Cb^GWwQA=2~J&NlHv~j*;(si!4t`CP|iX(kpJ5JohHai5uE) z^i4$QRNOQj88^v;amn(JH_791L*>&q$(FbY@{XJ2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|hUmd=e`|DG><<1q}XAPg3ie-9L%{tl%RVg&shg^_VP_z3hbrig5rZ;m_Z zGbJBEHsD9(L^ElDe4jp+;bN&1c#q3V6G=$1S!~H6(-`l>$qY-I zC@$mtD=B1G@icompE+c2cD=*pP;SqcqR`CwyFA=(Zr{TB0huyk<@_biw`O?reVnfw z#`q}$OGYS1&?6c>uJ-9r8hAR6?YsfSz5u))TSQ+(_LP|8svTye3=J(uV ze~KJwj|{>fOf2pGxHOqyrwfY7oWCT`gTQ5B9OwJ_=AXvn%;tP<5+kMv*SWBq3+MO< zS?-0lne+aMvf*NG@8JBBNV0Z;*`Ckam$>{Xmp_e{3HHp0;-A6O+q2MT+?Tlhtz_9= z88>~MqvQUO-xroqVdCa|l#$sd3+#yrWdlx6>M)o8Rl(;`NFpyTj3z}3gT!-*q;%o5 zxE;J_CKdoMi*Te1K`0`hESx6#rxS6J**={wm&x4fJ6J`Cv4Zjs8>fZalt;tLKaS`g zyB_iGRP*kzw+JX9IO1qG{rGs(xxJC|E%N>tEbw^}ED&e|pIb=FBC}YNM|u`bN75c& zYPO%@H+cjPvX=+R6-{2dG zy+hJ}%gVU$DPJa5?yw#_owXG{%gxU15AoYu$L(L?`~^M}yEwm(^AnYgtdoV0X#4;) zP?kq-K4l*9KHmmPcDc>{9_KTtB!GvUe~>_CmYHY1%Clq@Z*DXul+NP>&X;n23V1r4 z(-xUfR@p*se?FbGluh?d;cs#;C-*{?T?aVdVIkueo8#*EYFWeO4jwesL|$4vO_JG})53q;Tn)b>!AB(lc!9mT!1&ef65EbtTnnD%Mm# zXI?H$sam(Os$%7m8FQAXBrz2DN7h!34mmhd?)brxWMAc&;6k~kFCaHPwU`2uwNBNH1!OI1{7}_TBKuHNmZFv1 i^wjiLl2tWHXC-Ud_da~jCO4}l1uc+Ui6hUhP5OW6_R4br diff --git a/PA01-0906/build/Release/outRelease b/PA01-0906/build/Release/outRelease new file mode 100755 index 0000000000000000000000000000000000000000..5ef0f694c7a3db2742fd1e530115ad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s$QGTW<@{(r6aMNCS?B$LtFV8U~b;Pot zQT|rsAIBM%Y`;9`lXRjekH>O$#p_=Rl+O5M`Q1W)NnaKj)JC$MEH57alqz6UM3$H5 zijvB6M6j?c-u|@TMQ3!fygZkaRBSI8=aiC9(p4x=XMQp*&;2AVVYTu;GV3p3r42XK zC$c;}uhJ#yZk{yik8l4^kx%7k3qE$k{jP#QIV?0la=Sq3r3l?_8 z`_C_dn#(&xIZ64shbRmpvJLuFT>19VoL5rGFD1ydq#beP*NgI!mXLC$OO}(Ao?p%S z%Y7P27a@Y0FIi4vn{Z<;FZanMmHUyBKi+;@MS0o(a(__L5+j34a7aOdz6nb8OE!7F zBq{x_s`-kq|3hS&%dais+>%z);51#*e0z+hOy%YI zWcvTG{MRT;zANjO=WY&Bo_;TnE{Y#?$$Di!{tg(i$nx?%0(%{CyZLvIhh`b!h{+1H}M?1C_hs&3K}nOw5UHTo==p&A`T~A=`zze7h(Ci zqI|(9mQ*eUp;#dGm+=?dK8Eg`lmBdgkkf~V!F0)bB}Btjwq0UGNB Date: Mon, 4 Sep 2023 23:25:18 -0700 Subject: [PATCH 07/10] Update Makefile_Win +- Makefile for Windows --- PA01-0906/Makefile_Win | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PA01-0906/Makefile_Win b/PA01-0906/Makefile_Win index 87c154c..8d07827 100644 --- a/PA01-0906/Makefile_Win +++ b/PA01-0906/Makefile_Win @@ -2,10 +2,10 @@ CC = gcc -Wall SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o -all: PA01_Main.out +all: PA01_Main PA01_Main: $(OBJECTS) - $(CC) $(OBJECTS) -o PA01_Main + $(CC) $(OBJECTS) -o PA01_Main.exe PA01_Main.o: PA01_Main.c $(CC) -c PA01_Main.c -o PA01_Main.o From 5777809d47ba3fef9a60ab74cbb43a205ee8f720 Mon Sep 17 00:00:00 2001 From: cdez Date: Tue, 5 Sep 2023 23:06:04 -0700 Subject: [PATCH 08/10] Refined PA01 - File_IO +- EncryptionUtility.c +- outRelease (precompiled for UNIX style systems) NOTE: Use Make to compile for Windows systems --- PA01-0906/EncryptionUtility.c | 12 ++++++++++++ PA01-0906/build/Release/outRelease | Bin 36848 -> 36848 bytes 2 files changed, 12 insertions(+) diff --git a/PA01-0906/EncryptionUtility.c b/PA01-0906/EncryptionUtility.c index 5b5bfef..c4a5471 100644 --- a/PA01-0906/EncryptionUtility.c +++ b/PA01-0906/EncryptionUtility.c @@ -237,6 +237,12 @@ void downloadData( const char *fileName, const SquareArrayType data ) writeEndlineToFile(); } } + else + { + // if the file doesn't open, notify the user. + printf("\nThe file either doesn't exist," + "or you do not have permission to access it.\n"); + } // close file. closeOutputFile(); // no return. @@ -452,6 +458,12 @@ SquareArrayType *uploadData( const char *fileName ) } } } + else + { + // if the file doesn't open, notify the user. + printf("The file either doesn't exist," + "or you do not have permission to access it.\n"); + } // close file. closeInputFile(); // returns a Square Array. diff --git a/PA01-0906/build/Release/outRelease b/PA01-0906/build/Release/outRelease index 5ef0f694c7a3db2742fd1e530115adb9ae291dd8..b8f0a9245a8129f51b095ba7352dc71a665204c6 100755 GIT binary patch delta 6040 zcmb7Idsq}#mai%xwnVxcUp!Q35sb?FDIg$?fDJYVR#Aw6I1wLN6I2=_zQEA9X_1II zm|=I4)nwvmW}N+SNQ`k4MNrg)C?*=ir~wnB?GhCY&KUEk{oT6No#^-NA6wrCzp8V7 z_uO;O{oQ-3dSI6{uuE#uh(mWw6_jfSd5YogO?v*+q;Jg@!^Gjj9RB<((pKsA$S*Gh z3Ol#n*_c#zXh&LNMEk}+9?xst=JJs)VnT`_*f;$m%ch3pV0OQn-P>;CaezJ6jt~Ts z?T&q#H?Sf3C#o7@5Pziq7%@(~LWf2eN_vt7Aoc45Pm1q+Vc;ouD#`-&lpxOK~H|OLZw!IMRRAyNsYy(z|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Eh>N8A17-I1ujh&3)}LR zp7fQv(`d-bX;NPq%>$IrqE}Zg2y1Y#67XxBgK!ErLoja_g{^uH9of99Of08ct8%5i z4w~Rx5Z0pov(T&sh|nnusG&X1kc6%TZuYErGQ5M~@6?9DF{)lREy_VZICJqYENf+m zSV+Z{aZ-0W{l0Q_!l{P>1|yOU)0)H+tkDuBXm%GRtPTl_PvmBgkV-VKKnqvLi4NMl z`h|o;4`mi1ewMjgi(R2*Hfr`}n)zHBwzT}*eq^v##i1)Js&d0x#&P1amqAfzN=B=PxYs$oUnz^I<}a-SY67 zhZ5F6m})apD1802uqw?Bt9l*74O>nNtyv!z)}nPx-F)yfRjbv|(e-7L%R!?y#D?`* zc<4#IqS-YU@@AyKwqI|!Y7l49%uR8Ag}K~WNb;s!sa&E@H^mP6#Xp<}HKh(}DCC@m L!nXXTKTH1s%z4dr From ee473c78b1917fe4fe2cd1a791fce1b691b5135d Mon Sep 17 00:00:00 2001 From: cdez Date: Tue, 5 Sep 2023 23:37:29 -0700 Subject: [PATCH 09/10] Initialize PA02 ++ PA02 Files (StateUtilities) ++ STD LEV Utils ++ Makefile (Copied from PA01) --- PA02-0913/Console_IO_Utility.c | 590 ++++++++++++++++++++++++++ PA02-0913/Console_IO_Utility.h | 289 +++++++++++++ PA02-0913/File_Input_Utility.c | 717 ++++++++++++++++++++++++++++++++ PA02-0913/File_Input_Utility.h | 295 +++++++++++++ PA02-0913/File_Output_Utility.c | 511 +++++++++++++++++++++++ PA02-0913/File_Output_Utility.h | 236 +++++++++++ PA02-0913/Makefile | 32 ++ PA02-0913/Makefile_Win | 29 ++ PA02-0913/PA02_Main.c | 120 ++++++ PA02-0913/StandardConstants.h | 73 ++++ PA02-0913/StateUtilities.c | 0 PA02-0913/StateUtilities.h | 263 ++++++++++++ 12 files changed, 3155 insertions(+) create mode 100644 PA02-0913/Console_IO_Utility.c create mode 100644 PA02-0913/Console_IO_Utility.h create mode 100644 PA02-0913/File_Input_Utility.c create mode 100644 PA02-0913/File_Input_Utility.h create mode 100644 PA02-0913/File_Output_Utility.c create mode 100644 PA02-0913/File_Output_Utility.h create mode 100644 PA02-0913/Makefile create mode 100644 PA02-0913/Makefile_Win create mode 100644 PA02-0913/PA02_Main.c create mode 100644 PA02-0913/StandardConstants.h create mode 100644 PA02-0913/StateUtilities.c create mode 100644 PA02-0913/StateUtilities.h diff --git a/PA02-0913/Console_IO_Utility.c b/PA02-0913/Console_IO_Utility.c new file mode 100644 index 0000000..38b9f46 --- /dev/null +++ b/PA02-0913/Console_IO_Utility.c @@ -0,0 +1,590 @@ +// Header files included +#include "Console_IO_Utility.h" + +// Function Implementations + +/* +Name: clearLeadingCharacters +Process: Clears all leading non-printable characters from the console stream +Function input/parameters: allow space return (Boolean) +Function output/parameters: none +Function output/returned: first printable character as integer +Device input/keyboard: none +Device output/monitor: none +Dependencies: getchar +*/ +int clearLeadingCharacters( bool allowSpaceReturn ) + { + // initialize data, set input character to getChar, set count to zero + // function: getchar + int intChar = getchar(); + int charCount = 0; + + // loop while non-printable characters and space if not set + // also limits looping to constant limit + while( ( intChar < (int)SPACE + || ( !allowSpaceReturn && intChar == SPACE ) ) + && charCount < MAX_STR_LEN ) + { + // update character count + charCount++; + + // get new input character + // function: getchar + intChar = getchar(); + } + + // return captured character + return intChar; + } + +/* + +Name: getChar +Process: returns next character in stream, + ignores all white space (including SPACE) prior to character +Function input/parameters: flag to accept space (Boolean) +Function output/parameters: none +Function output/returned: one character (char) is returned to calling method +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: getCharFiltered +*/ +char getChar() + { + // initialize variables, set space accept flag to false + bool dontAcceptSpace = false; + + // call filtered function with space accept flag + // function: getCharFiltered + return getCharFiltered( dontAcceptSpace ); + } + +/* +Name: getCharFiltered +Process: returns next character in stream, + ignores non printable characters prior to input character + but may accept space depending on flag +Function input/parameters: flag to accept space (boolean) +Function output/parameters: none +Function output/returned: first printable character or space (if configured) + returned (char) +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +char getCharFiltered( bool acceptSpace ) + { + //Initialize variables + int inCharInt; + + // clear leading characters, capture first usable character + // function: clearLeadingCharacters + inCharInt = clearLeadingCharacters( acceptSpace ); + + // check for input character set to end of file + if( inCharInt == EOF ) + { + // return character zero + return '0'; + } + + // return input character as character + return (char)inCharInt; + } + +/* +Name: getInputString +Process: acquires input string from keyboard, if clear white space flag set, + ignores all white space, including space character +Function input/parameters: clear white space control (Boolean) +Function output/parameters: character array (char[]) +Function output/returned: none +Device input/keyboard: user entry of a character stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +void getInputString( char inputArr[], bool clearWhiteSpace ) + { + //Initialize Variables, set character count and index to zero + int charCount = 0; + int index = 0; + int intChar; + + // check for clear white space flag + if( clearWhiteSpace ) + { + // clear leading characters, set flag to ignore space + // function: clearLeadingCharacters + intChar = clearLeadingCharacters( !clearWhiteSpace ); + } + + // otherwise, assume white space flag not set + else + { + // get first character + // function: getchar + intChar = getChar(); + } + + // loop until enter key found, limit loop to constant + while( intChar != (int)NEWLINE_CHAR && charCount < MAX_STR_LEN ) + { + // set current value to array element + inputArr[ index ] = (char)intChar; + + // increment string array index + index++; + + // add null character to end of string array + inputArr[ index ] = NULL_CHAR; + + // increment character count + charCount++; + + // get next character + // function: getchar + intChar = getchar(); + } + } + +/* +Name: printCharacter +Process: prints a single character +Function input/parameters: character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: character printed as specified +Dependencies: printCharacters +*/ +void printCharacter( char outputChar ) + { + // initialize number of characters to one + int numberOfChars = 1; + + // print one character + // function: printChars + printCharacters( numberOfChars, outputChar ); + } + +/* +Name: printCharacters +Process: prints given number of characters +Function input/parameters: number of characters (int), + character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: Number of specified characters printed +Dependencies: printf +*/ +void printCharacters( int numChars, char outputChar ) + { + // check for reminaing characters to print + if( numChars > 0 ) + { + // print one character + // function: printf + printf( "%c", outputChar ); + + // (recursive) print remaining characters + // function: printChars + printCharacters( numChars - 1, outputChar ); + } + } + +/* +Name: printDouble +Process: simple print double function +Function input/parameters: + outVal - the double value to be output (double) + precision - the number of digits to the right of the decimal point (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed +Dependencies: printDoubleJustified +*/ +void printDouble( double outVal, int precision ) + { + // initialize variables, set block size to zero and justified to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // call justified function with specified parameters + // function: printDoubleJustified + printDoubleJustified( outVal, precision, blockSize, justified ); + } + +/* +Name: printDoubleJustified +Process: the precision is set for the double value, then the pre-spaces + and post-spaces are calculated for the requested justification, + and then the pre-spaces are printed, the double value is printed, + and then the post-spaces are printed +Function input/parameters: + outVal - the double value to be output (double) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed, justified, with precision +Dependencies: formatDouble, printStringJustified +*/ +void printDoubleJustified( double outVal, int precision, + int blockSize, const char* justify ) + { + // initialize variables, create temp string for configuration string + char specStr[ MIN_STR_LEN ]; + + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // set configuration string with precision value + // function: sprintf + sprintf( specStr, "%s0.%dlf", "%", precision ); + + // set output string + // function: sprintf + sprintf( outStr, specStr, outVal ); + + // print string justified + // function: printStringJustified + printStringJustified( outStr, blockSize, justify ); + } + +/* +Name: printEndline +Process: prints single endline character to end a line or create vertical space +Function input/parameters: none +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one endline character output +Dependencies: printf +*/ +void printEndline() + { + // print one newline character + // function: printf + printf( "\n" ); + } + +/* +Name: printEndlines +Process: prints the specified number of endline characters + to end a line and/or create vertical space(s) +Function input/parameters: number of endlines (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: endline characters output as specified +Dependencies: printEndline +*/ +void printEndlines( int numEndlines ) + { + // check for number of end lines remaining + if( numEndlines > 0 ) + { + // print one endling + // function: printEndline + printEndline(); + + // (recursive) print remaining end lines + printEndlines( numEndlines - 1 ); + } + } + +/* + Name: printInteger + Process: prints integer value +Function input/parameters: outVal - the integer value to be output + Output: None + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: printIntegerJustified + */ +void printInteger( int outVal ) + { + // initialize variables, set block size to zero, justifification to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // print justified integer with specified parameters + // function: printIntegerJustified + printIntegerJustified( outVal, blockSize, justified ); + } + +/* + Name: printIntegerJustified + Process: prints integer value with the specified justification + within the specified blockSize +Function input/parameters: + outVal - the integer value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) + Output: None + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: sprintf, printStringJustified + */ +void printIntegerJustified( int outVal, int blockSize, const char *justify ) + { + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // convert integer to string + // function: sprintf + sprintf( outStr, "%d", outVal ); + + // print justified string + // function: printStringJustified + printStringJustified( outStr, blockSize, justify ); + } + +/* +Name: printLongInteger +Process: prints long integer +Function input/Parameters: outVal - the long integer value to be output +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: printLongIntJustified +*/ +void printLongInteger( long outVal ) + { + // initialize variables, set block size to zero, justification to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // print justified long integer with specified parameters + // function: printLongIntegerJustified + printLongIntegerJustified( outVal, blockSize, justified ); + } + +/* +Name: printLongIntegerJustified +Process: prints long integer with the specified justification + within the specified blockSize +Function input/Parameters: + outVal - the long integer value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: sprintf, printStringJustified +*/ +void printLongIntegerJustified( long outVal, + int blockSize, const char *justify ) + { + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // convert long integer to string + // function: sprintf + sprintf( outStr, "%ld", outVal ); + + // print justified string + // function: printStringJustified + printStringJustified( outStr, blockSize, justify ); + } + +/* + Name: printString + Process: prints string +Function input/parameters: outVal - the string value to be output +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: printStringJustified +*/ +void printString( const char *outStr ) + { + // initialize variables, set block size to zero, justification to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // print justified string with specified parameters + // function: printStringJustified + printStringJustified( outStr, blockSize, justified ); + } + +/* + Name: printStringJustified + Process: prints string within specified block size + and with specified justification +Function input/parameters: + outVal - the string value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: strlen, strcmp, printCharacters, printf +*/ +void printStringJustified ( const char *outStr, + int blockSize, const char *justify ) + { + // initialize variables, set pre-, post- spaces to zero + int preSpaces = 0, postSpaces = 0, strLength; + + // find length of string + // function: strlen + strLength = strlen( outStr ); + + // check justification for "LEFT" + // function: strcmp + if( strcmp( justify, "LEFT" ) == 0 ) + { + // set post spaces for left justification + postSpaces = blockSize - strLength; + } + + // otherwise, check justification for "RIGHT" + // function: strcmp + else if( strcmp( justify, "RIGHT" ) == 0 ) + { + // set pre spaces for right justification + preSpaces = blockSize - strLength; + } + + // Otherwise, assume "CENTER" justification + else + { + // set pre spaces for centered + preSpaces = blockSize / 2 - strLength / 2; + + // set post spaces for centered + postSpaces = blockSize - strLength - preSpaces; + } + + // print pre spaces + // function: printChars + printCharacters( preSpaces, SPACE ); + + // print string + // function: printf + printf( "%s", outStr ); + + // print post spaces + // function: printChars + printCharacters( postSpaces, SPACE ); + } + +/* +Name: promptForCharacter +Process: prompts user for character, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: None +Function output/returned: one character (chars +Device input/keyboard: user entry of a character +Device output/monitor: prompt string displayed +Dependencies: printf, getChar +*/ +char promptForCharacter( const char *promptString ) + { + // initialize variables + char outChar; + + // print prompt string + // function: printf + printf( "%s", promptString ); + + // get character from stream + // function: getChar + outChar = (char)getChar(); + + // return captured character + return outChar; + } + +/* +Name: promptForDouble +Process: prompts user for double, then returns it +Function input/parameters: test to prompt user (c-string) +Function output/parameters: None +Function output/returned: value (double) +Device input/keyboard: user entry of an integer value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf + */ +double promptForDouble( const char *promptString ) + { + // initialize variables + double outDouble; + + // print prompt string + // function: printf + printf( "%s", promptString ); + + // get double value + // function: scanf + scanf( "%lf", &outDouble ); + + // return captured double + return outDouble; + } + +/* +Name: promptForInteger +Process: prompts user for integer, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: none +Function output/returned: integer value (int) +Device input/keyboard: user entry of a double value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf +*/ +int promptForInteger( const char *promptString ) + { + // initialize variables + int outInt; + + // print prompt string + // function: printf + printf( "%s", promptString ); + + // input integer + // function: scanf + scanf( "%d", &outInt ); + + // return captured integer + return outInt; + } + +/* +Name: promptForString +Process: prompts user for string, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: input string from user(c-string) +Function output/returned: none +Device input/keyboard: user entry of a string value +Device output/monitor: prompt string displayed +Dependencies: printf, getInputString +*/ +void promptForString( const char *promptString, char returnStr[] ) + { + // initialize variables, don't allow white space capture + bool dontClearWhitespace = false; + + // pring prompt string + // function: printf + printf( "%s", promptString ); + + // get input string from user (returned via parameter) + // function: getInputString + getInputString( returnStr, dontClearWhitespace ); + } + + diff --git a/PA02-0913/Console_IO_Utility.h b/PA02-0913/Console_IO_Utility.h new file mode 100644 index 0000000..cb76f1c --- /dev/null +++ b/PA02-0913/Console_IO_Utility.h @@ -0,0 +1,289 @@ +// Preprocessor directive +#ifndef CONSOLE_IO_UTILITY_H +#define CONSOLE_IO_UTILITY_H + +//Header Files +#include +#include +#include +#include "StandardConstants.h" + +//Global Constants + + // none + +//Function Prototypes + +/* +Name: clearLeadingCharacters +Process: Clears all leading non-printable characters from the console stream +Function input/parameters: allow space return (bool) +Function output/parameters: none +Function output/returned: first printable character as integer +Device input/keyboard: none +Device output/monitor: none +Dependencies: getchar +*/ +int clearLeadingCharacters( bool allowSpaceReturn ); + +/* +Name: getChar +Process: returns next character in stream, + ignores all white space (including SPACE) prior to character +Function input/parameters: flag to accept space (bool) +Function output/parameters: none +Function output/returned: one character (char) is returned to calling method +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: +*/ +char getChar(); + +/* +Name: getCharFiltered +Process: returns next character in stream, + ignores non printable characters prior to input character + but may accept space depending on flag +Function input/parameters: flag to accept space (bool) +Function output/parameters: none +Function output/returned: first printable character or space (if configured) + returned (char) +Device input/keyboard: places one or more characters in stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +char getCharFiltered( bool acceptSpace ); + +/* +Name: getInputString +Process: acquires input string from keyboard, if clear white space flag set, + ignores all white space, including space character +Function input/parameters: clear white space control (bool) +Function output/parameters: character array (char[]) +Function output/returned: none +Device input/keyboard: user entry of a character stream +Device output/monitor: none +Dependencies: getchar(), clearLeadingCharacters +*/ +void getInputString(char inputArr[], bool clearWhiteSpace ); + +/* +Name: printCharacter +Process: prints a single character +Function input/parameters: character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: character printed as specified +Dependencies: printCharacters +*/ +void printCharacter( char outputChar ); + +/* +Name: printCharacters +Process: prints given number of characters +Function input/parameters: number of characters (int), + character to be printed (char) +Function output/parameters: None +Function output/returned: None +Device input/keyboard: None +Device output/monitor: Number of specified characters printed +Dependencies: printf +*/ +void printCharacters( int numChars, char outputChar ); + +/* +Name: printDouble +Process: simple print double function +Function input/parameters: + outVal - the double value to be output (double) + precision - the number of digits to the right of the decimal point (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed +Dependencies: printDoubleJustified +*/ +void printDouble( double outVal, int precision ); + +/* +Name: printDoubleJustified +Process: the precision is set for the double value, then the pre-spaces + and post-spaces are calculated for the requested justification, + and then the pre-spaces are printed, the double value is printed, + and then the post-spaces are printed +Function input/parameters: + outVal - the double value to be output (double) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one double value displayed, justified, with precision +Dependencies: formatDouble, printStringJustified +*/ +void printDoubleJustified( double outVal, int precision, + int blockSize, const char* justify ); + +/* +Name: printEndline +Process: prints single endline character to end a line or create vertical space +Function input/parameters: none +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: one endline character output +Dependencies: printEndline +*/ +void printEndline(); + +/* +Name: printEndlines +Process: prints the specified number of endline characters + to end a line and/or create vertical space(s) +Function input/parameters: number of endlines (int) +Function output/parameters: none +Function output/returned: none +Device input: none +Device output/monitor: endline characters output as specified +Dependencies: printEndline +*/ +void printEndlines( int numEndlines ); + +/* + Name: printInteger + Process: prints integer value + Function input/parameters: outVal - the integer value to be output + Function output/parameters: None + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: printIntegerJustified + */ +void printInteger( int outVal ); + +/* + Name: printIntegerJustified + Process: prints integer value with the specified justification + within the specified blockSize + Function input/parameters: + outVal - the integer value to be output (int) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) + Function output/parameters: none + Device Input: None + Device Output: Integer is displayed as specified + Dependencies: sprintf, printStringJustified + */ +void printIntegerJustified( int outVal, int blockSize, const char *justify ); + +/* +Name: printLongInteger +Process: prints long integer +Function input/Parameters: outVal - the long integer value to be output +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: printLongIntJustified +*/ +void printLongInteger( long outVal ); + +/* +Name: printLongIntegerJustified +Process: prints long integer with the specified justification + within the specified blockSize +Function Input/Parameters: + outVal - the long integer value to be output (long int) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Device Input/keyboard: None +Device Output/Monitor: integer is displayed as specified +Dependencies: sprintf, printStringJustified +*/ +void printLongIntegerJustified( long outVal, + int blockSize, const char *justify ); + +/* + Name: printString + Process: prints string +Function input/parameters: outVal - the string value to be output +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: printStringJustified +*/ +void printString( const char *outStr ); + +/* + Name: printStringJustified + Process: prints string within specified block size + and with specified justification +Function input/parameters: + outStr - the string value to be output (c-string) + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification in block (c-string) +Function output/parameters: None +Function output/returned: None +Function input/keyboard: None +Device output/monitor: string is displayed as specified +Dependencies: strlen, strcmp, printCharacters, printf +*/ +void printStringJustified( const char *outStr, + int blockSize, const char *justify ); + +/* +Name: promptForCharacter +Process: prompts user for character, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: None +Function output/returned: one character (chars +Device input/keyboard: user entry of a character +Device output/monitor: prompt string displayed +Dependencies: printf, getChar +*/ +char promptForCharacter( const char *promptString ); + +/* +Name: promptForDouble +Process: prompts user for double, then returns it +Function input/parameters: test to prompt user (c-string) +Function output/parameters: None +Function output/returned: value (double) +Device input/keyboard: user entry of an integer value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf + */ +double promptForDouble( const char *promptString ); + +/* +Name: promptForInteger +Process: prompts user for integer, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: none +Function output/returned: integer value (int) +Device input/keyboard: user entry of a double value +Device output/monitor: prompt string displayed +Dependencies: printf, scanf +*/ +int promptForInteger( const char *promptString ); + +/* +Name: promptForString +Process: prompts user for string, then returns it +Function input/parameters: text to prompt user (c-string) +Function output/parameters: input string captured (c-string) +Function output/returned: none +Device input/keyboard: user entry of a string value +Device output/monitor: prompt string displayed +Dependencies: printf, getInputString +*/ +void promptForString( const char *promptString, char returnStr[] ); + +#endif // end CONSOLE_IO_UTILITY_H diff --git a/PA02-0913/File_Input_Utility.c b/PA02-0913/File_Input_Utility.c new file mode 100644 index 0000000..a7bbd68 --- /dev/null +++ b/PA02-0913/File_Input_Utility.c @@ -0,0 +1,717 @@ +/* +Formatted file input utility, function implementations + +Copyright (c) 2021 by Michael E. Leverington + +Code is free for use in whole or in part and may be modified for other +non-commercial use as long as the above copyright statement is included. +*/ + +// header files +#include "File_Input_Utility.h" +#include //////////////////////////test + +// local global constants, used only in this file + + // dummy file pointer for accessInputFilePointer + const FILE *DUMMY_INPUT_FILE_PTR = NULL; + + // dummy Boolean for accessEndOfInputFileFlag, accessOpenFlag + const char DUMMY_INPUT_FLAG = false; + + // control code for accessing file pointer, accessInputFilePointer + const int GET_INPUT_FILE_PTR = 3003; + + // control code for accessing flag value, + // accessEndOfInputFileFlag, accessOpenFlag + const int GET_INPUT_FLAG = 2002; + + // control code for setting file pointer, accessInputFilePointer + const int SET_INPUT_FILE_PTR = 4004; + + // control code for setting flag value, accessEndOfInputFileFlag, + // accessOpenFlag + const int SET_INPUT_FLAG = 1001; + + + /* + Name: accessEndOfInputFileFlag + process: allows accessing or modifying end of file flag state; + note: flag is maintained (static) value initialized to false + Function input/parameters: control code (int), flag state (bool) + Function output/parameters: none + Function output/returned: result of flag state (bool) + Device input/file: none + Device output/monitor: none + Dependencies: none + */ + bool accessEndOfInputFileFlag( int ctrlCode, bool setFlag ) + { + // initialize end of file flag to false + static bool endOfFileFlag = false; + + // test for set flag + if( ctrlCode == SET_INPUT_FLAG ) + { + // set flag to given state + endOfFileFlag = setFlag; + } + + // return flag state + return endOfFileFlag; + } + + /* + Name: accessInputFilePointer + process: allows setting or accessing file pointer; + note: pointer is maintained (static) value initialized to NULL + Function input/parameters: control code (int), file pointer (FILE *) + DUMMY_INPUT_FILE_PTR used + if not setting file pointer + Function output/parameters: none + Function output/returned: file pointer (FILE *) + Device input/file: none + Device output/monitor: none + Dependencies: none + */ + FILE *accessInputFilePointer( int ctrlCode, const FILE *filePtr ) + { + // initialize file pointer to null + static FILE *filePointer = NULL; + + // check for set new pointer + if( ctrlCode == SET_INPUT_FILE_PTR ) + { + // set file pointer to parameter + filePointer = (FILE *)filePtr; + } + + // return file pointer + return filePointer; + } + + /* + Name: checkForEndOfInputFile + process: checks to see if end of file flag has been encountered, + returns true if EOF has been encountered, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: result of specified test (bool) + Device input/file: none + Device output/monitor: none + Dependencies: accessEndOfInputFileFlag + */ + bool checkForEndOfInputFile() + { + // return access to end of file flag + // function: accessEndOfInputFileFlag + return accessEndOfInputFileFlag( GET_INPUT_FLAG, DUMMY_INPUT_FLAG ); + } + + /* + Name: checkForInputFileOpen + process: checks to see if file is currently open + returns true if file pointer not null, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: result of specified test (bool) + Device input/file: none + Device output/monitor: none + Dependencies: accessInputFilePointer + */ + bool checkForInputFileOpen() + { + // return access to end of file flag + // function: accessInputFilePointer + return accessInputFilePointer( GET_INPUT_FLAG, + DUMMY_INPUT_FILE_PTR ) != NULL; + } + + /* + Name: clearLeadingWhiteSpace + process: captures non printable characters, + and space if flag set, + returns first non white space value found as integer + Function input/parameters: file pointer (FILE *), clear space flag (bool) + Function output/parameters: none + Function output/returned: first non WS character as integer + Device input/file: value captured from file + Device output/monitor: none + Dependencies: fgetc + */ + int clearLeadingWhiteSpace( FILE *filePtr, bool clearSpace ) + { + // initialize character input value + // function: fgetc + int charInt = fgetc( filePtr ); + + while( + // continue if not at end of file + ( charInt != EOF ) + + // AND + // continue if character is non printable + && ( ( charInt < (int)SPACE || charInt > (int)HIGHEST_PRINTABLE_CHAR ) + + // OR + // continue if clear space flag set and space is found + || ( clearSpace && charInt == SPACE ) ) + ) + { + // capture next character + // function: fgetc + charInt = fgetc( filePtr ); + } + + // return input value as character + return (char)charInt; + } + + /* + Name: closeInputFile + process: closes input file, returns true if successful, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: none + Device input/file: file closed + Device output/monitor: none + Dependencies: accessInputFilePointer, fclose, accessEndOfInputFileFlag + */ + bool closeInputFile() + { + // set local file pointer to working file pointer + // function: accessInputFilePointer + FILE *filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // check for valid file pointer + if( filePtr != NULL ) + { + // close file + fclose( filePtr ); + + // set pointer to NULL + // function: accessInputFilePointer + accessInputFilePointer( SET_INPUT_FILE_PTR, NULL ); + + // set end of file flag to false + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, false ); + + // return successful operation + return true; + } + + // return failed operation + return false; + } + + /* + Name: openInputFile + process: opens input file, sets file pointer and unsets end of file flag, + returns true if successful, false otherwise + Function input/parameters: file name (c-string) + Function output/parameters: none + Function output/returned: success of operation (bool) + Device input/file: file opened + Device output/monitor: none + Dependencies: fopen, accessInputFilePointer, accessEndOfInputFileFlag + */ + bool openInputFile( const char *fileName ) + { + // initialize variables + FILE *filePtr = NULL; + char readOnlyCharacter[] = "r"; + + // check for file not open + // function: checkForInputFileOpen + if( !checkForInputFileOpen() ) + { + // open file + // function: fopen + filePtr = fopen( fileName, readOnlyCharacter ); + + // check for success of file open + if( filePtr != NULL ) + { + // set pointer in access function + // function: accessInputFilePointer + accessInputFilePointer( SET_INPUT_FILE_PTR, filePtr ); + + // reset end of file flag, if needed + // accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, false ); + + // return operation success + return true; + } + } + // end of file not previously opened block + + // return operation failure + return false; + } + + /* + Name: readCharacterFromFile + process: ignores leading unprintable characters, including space, + captures first printable character + Function input/parameters: allow space capture (bool) + Function output/parameters: none + Function output/returned: character found if successful, ZERO_CHAR otherwise + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readCharacterFromFileConfigured + */ + char readCharacterFromFile() + { + // initialize parameter to not allow space + bool noSpaceCapture = false; + + // capture character, return + // function: getCharFromFileConfigured + return readCharacterFromFileConfigured( noSpaceCapture ); + } + + /* + Name: readCharacterFromFileConfigured + process: ignores leading unprintable characters, + captures first printable character, + including space if allowed + Function input/parameters: allow space capture (bool) + Function output/parameters: none + Function output/returned: character found if successful, ZERO_CHAR otherwise + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, clearLeadingWhiteSpace, + accessEndOfInputFileFlag + */ + char readCharacterFromFileConfigured( bool captureSpace ) + { + // initialize variables + FILE *filePtr; + int intChar = ZERO_CHAR; + + // check for file open and data accessible + // function: checkForInputFileOpen, checkForEndOfInputFile + if( checkForInputFileOpen() && !checkForEndOfInputFile() ) + { + // set file pointer + // function: accessInputFilePointer + filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // get character + // function: clearLeadingWhiteSpace + intChar = clearLeadingWhiteSpace( filePtr, !captureSpace ); + + // check for end of file found + if( intChar == EOF ) + { + // set end of file flag + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, true ); + + // set return value to zero + intChar = ZERO_CHAR; + } + } + + // return value as character + return intChar; + } + + /* + Name: readDoubleFromFile + process: ignores leading unprintable characters, + captures first contiguous double value + Function input/parameters: none + Function output/parameters: none + Function output/returned: double value found if successful (double) + Device input/file: double value captured from file + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fscanf, accessEndOfInputFileFlag + */ + double readDoubleFromFile() + { + // initialize variables + FILE *filePtr = NULL; + int fscanfReturn = EOF; + double doubleVal = ZERO_VALUE; + + // check for file open and data accessible + // function: checkForInputFileOpen, checkForEndOfInputFile + if( checkForInputFileOpen() && !checkForEndOfInputFile() ) + { + // set file pointer + // function: accessInputFilePointer + filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // get double value + // function: fscanf + fscanfReturn = fscanf( filePtr, "%lf", &doubleVal ); + + // check for end of file found + if( fscanfReturn == EOF ) + { + // set end of file flag + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, true ); + + // set return value to zero + doubleVal = ZERO_VALUE; + } + } + + // return acquired value + return doubleVal; + } + + /* + Name: readIntegerFromFile + process: ignores leading unprintable characters, + captures first contiguous integer + Function input/parameters: none + Function output/parameters: none + Function output/returned: integer found if successful, ZERO_VALUE otherwise + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fscanf, accessEndOfInputFileFlag + */ + int readIntegerFromFile() + { + // initialize variables + FILE *filePtr = NULL; + int fscanfReturn = EOF; + int intVal = ZERO_VALUE; + + // check for file open and data accessible + // function: checkForInputFileOpen, checkForEndOfInputFile + if( checkForInputFileOpen() && !checkForEndOfInputFile() ) + { + // set file pointer + // function: accessInputFilePointer + filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // get integer value + // function: fscanf + fscanfReturn = fscanf( filePtr, "%d", &intVal ); + + // check for end of file found + if( fscanfReturn == EOF ) + { + // set end of file flag + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, true ); + + // set return value to zero + intVal = ZERO_VALUE; + } + } + + // return acquired value + return intVal; + } + + /* + Name: readLongFromFile + process: ignores leading unprintable characters, + captures first contiguous long int + Function input/parameters: none + Function output/parameters: none + Function output/returned: long integer found if successful, + ZERO_VALUE otherwise + Device input/file: long value captured from file + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fscanf, accessEndOfInputFileFlag + */ + long readLongFromFile() + { + // initialize variables + FILE *filePtr = NULL; + int fscanfReturn = EOF; + long longVal = ZERO_VALUE; + + // check for file open and data accessible + // function: checkForInputFileOpen, checkForEndOfInputFile + if( checkForInputFileOpen() && !checkForEndOfInputFile() ) + { + // set file pointer + // function: accessInputFilePointer + filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // get long value + // function: fscanf + fscanfReturn = fscanf( filePtr, "%ld", &longVal ); + + // check for end of file found + if( fscanfReturn == EOF ) + { + // set end of file flag + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, true ); + + // set return value to zero + longVal = ZERO_VALUE; + } + } + + // return acquired value + return longVal; + } + + /* + Name: readRawCharFromFile + process: captures first character in file stream including non-printable + Function input/parameters: none + Function output/parameters: none + Function output/returned: character found if successful, ZERO_CHAR otherwise + Device input/file: character captured from file + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fgetc, accessEndOfInputFileFlag + */ + char readRawCharFromFile() + { + // initialize variables + FILE *filePtr = NULL; + int intChar = (int)ZERO_CHAR; + + // check for file open and data accessible + // function: checkForInputFileOpen, checkForEndOfInputFile + if( checkForInputFileOpen() && !checkForEndOfInputFile() ) + { + // set file pointer + // function: accessInputFilePointer + filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // get character + // function: fgetc + intChar = fgetc( filePtr ); + + // check for end of file found + if( intChar == EOF ) + { + // set end of file flag + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, true ); + + // set return value to zero + intChar = (int)ZERO_CHAR; + } + } + + // return acquired value + return (char)intChar; + } + + /* + Name: readStringConfiguredFromFile + Process: captures string with options: + - clear leading non printable (bool) + - clear leading space character (bool) + - adquires characters up to any non-printable (bool) + - adquires characters up to any printable delimiter (char) + - use constant NON_PRINTABLE if no delimiter + - also stops capture when full (MAX_STR_LEN) + Note: This function consumes the last character input, + including the space, delimiter, or non-printable character + Function input/parameters: see process above + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: success of operation (bool) + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + clearLeadingWhiteSpace, fgetc, accessEndOfInputFileFlag + */ + bool readStringConfiguredFromFile( bool clearLeadingNonPrintable, + bool clearLeadingSpace, + bool stopAtNonPrintable, + char delimiter, + char *capturedString ) + { + // initialize variables + int intChar = EOF, index = 0; + FILE *filePtr = NULL; + + // initialize output string + capturedString[ index ] = NULL_CHAR; + + // check for file open and data accessible + // function: checkForInputFileOpen, checkForEndOfInputFile + if( checkForInputFileOpen() && !checkForEndOfInputFile() ) + { + // get file pointer + // function: accessFilePtr + filePtr = accessInputFilePointer( GET_INPUT_FILE_PTR, + DUMMY_INPUT_FILE_PTR ); + + // check for clearing non printable + if( clearLeadingNonPrintable ) + { + // clear leading white space, with clear space character flag + // function: clearLeadingWhiteSpace + intChar = clearLeadingWhiteSpace( filePtr, clearLeadingSpace ); + } + + // otherwise, assume non printable not cleared + else + { + // get first character + // function: fgetc + intChar = fgetc( filePtr ); + + // check for clearing spaces + if( clearLeadingSpace ) + { + // loop while spaces found and end of file not found + while( intChar != EOF && intChar == (int)SPACE ) + { + // capture new character + // function: fgetc + intChar = fgetc( filePtr ); + } + } + } // end leading character clearing process + + // check for end of file found + if( intChar == EOF ) + { + // set end of file flag + // function: accessEndOfInputFileFlag + accessEndOfInputFileFlag( SET_INPUT_FLAG, true ); + + // return failed operation + return false; + } + + // loop to capture input + while( + // continues if not at end of file and max string length not reached + ( intChar != EOF && index < MAX_STR_LEN - 1 ) + + // AND + // continues if not printable flag set and characters are printable + // OR not printable flag not set + && ( ( stopAtNonPrintable && intChar >= (int)SPACE ) + || ( !stopAtNonPrintable ) ) + + // AND + // continues if specified delimiter is not found + && ( intChar != (char)delimiter ) + ) + { + // place character in array element + capturedString[ index ] = (char)intChar; + + // increment array index + index++; + + // set next element to null character / end of c-string + capturedString[ index ] = NULL_CHAR; + + // get next character as integer + // function: fgetc + intChar = fgetc( filePtr ); + } + // end loop + + // return successful operation + return true; + } + // end of open file and accessible data block + + return false; // temporary stub return + } + + /* + Name: readStringSegmentFromFile + process: ignores leading white space, including space character, + captures series of characters up to first space, + or end of line, or full string + Function input/parameters: none + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: success of operation (bool) + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readStringConfigured with appropriate parameters + */ + bool readStringSegmentFromFile( char *capturedString ) + { + // initialize variables + bool clearLeadingNonPrintable = true; + bool clearLeadingSpace = true; + bool stopAtNonPrintable = true; + char delimiter = SPACE; + + // call utility function, return + return readStringConfiguredFromFile( clearLeadingNonPrintable, + clearLeadingSpace, + stopAtNonPrintable, + delimiter, + capturedString ); + } + + /* + Name: readStringToLineEndFromFile + process: ignores leading white space, including space character, + captures series of characters up to end of current line + or full string + Function input/parameters: none + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: string found if successful + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readStringConfigured with appropriate parameters + */ + bool readStringToLineEndFromFile( char *capturedString ) + { + // initialize variables + bool clearLeadingNonPrintable = true; + bool clearLeadingSpace = true; + bool stopAtNonPrintable = true; + char delimiter = NON_PRINTABLE; + + // call utility function, return + return readStringConfiguredFromFile( clearLeadingNonPrintable, + clearLeadingSpace, + stopAtNonPrintable, + delimiter, + capturedString ); + } + + /* + Name: readStringToDelimiterFromFile + process: ignores leading white space, including space character, + captures series of characters up to specified character + Function input/parameters: none + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: string found if successful + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readStringConfigured with appropriate parameters + */ + bool readStringToDelimiterFromFile( char delimiter, char *capturedString ) + { + // initialize variables + bool clearLeadingNonPrintable = true; + bool clearLeadingSpace = true; + bool stopAtNonPrintable = true; + + // call utility function, return + return readStringConfiguredFromFile( clearLeadingNonPrintable, + clearLeadingSpace, + stopAtNonPrintable, + delimiter, + capturedString ); + } + + diff --git a/PA02-0913/File_Input_Utility.h b/PA02-0913/File_Input_Utility.h new file mode 100644 index 0000000..70d3552 --- /dev/null +++ b/PA02-0913/File_Input_Utility.h @@ -0,0 +1,295 @@ +/* +Formatted file input utility, function prototypes + +Copyright (c) 2021 by Michael E. Leverington + +Code is free for use in whole or in part and may be modified for other +non-commercial use as long as the above copyright statement is included. +*/ +/* +Rev 0.0: 30 June 2021, Initial creation of file + +UTILITY USAGE INSTRUCTIONS: + +1) This utility contains functions that may be used for file input operations + using the C programming language with text files. + The utility must be linked with the program code with which + it will be used. + +2) Specifications for all the functions + are provided in a standardized format below. + +3) Use this code at your own risk. There is no guarantee of any performance, + implied or otherwise, for any part of this code + + END OF INSTRUCTIONS +*/ + +// PreProcessor test +#ifndef FILE_INPUT_UTILITY_H +#define FILE_INPUT_UTILITY_H + +// header files +#include +#include +#include "StandardConstants.h" + +// constants shared with other files + + // non printable flag, used in getStringConfigured + static const char NON_PRINTABLE = (char)(127); + + // constant used for zero character return + static const char ZERO_CHAR = '0'; + + // constant used for zero int/double value return + static const char ZERO_VALUE = 0; + +// function prototypes + + /* + Name: accessEndOfInputFileFlag + process: allows accessing or modifying end of file flag state; + note: flag is maintained (static) value initialized to false + Function input/parameters: control code (int), flag state (bool) + Function output/parameters: none + Function output/returned: result of flag state (bool) + Device input/file: none + Device output/monitor: none + Dependencies: none + */ + bool accessEndOfInputFileFlag( int ctrlCode, bool setFlag ); + + /* + Name: accessInputFilePointer + process: allows setting or accessing file pointer; + note: pointer is maintained (static) value initialized to NULL + Function input/parameters: control code (int), file pointer (FILE *) + DUMMY_INPUT_FILE_PTR used + if not setting file pointer + Function output/parameters: none + Function output/returned: file pointer (FILE *) + Device input/file: none + Device output/monitor: none + Dependencies: none + */ + FILE *accessInputFilePointer( int ctrlCode, const FILE *filePtr ); + + /* + Name: checkForEndOfInputFile + process: checks to see if end of file flag has been encountered, + returns true if EOF has been encountered, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: result of specified test (bool) + Device input/file: none + Device output/monitor: none + Dependencies: accessEndOfInputFileFlag + */ + bool checkForEndOfInputFile(); + + /* + Name: checkForInputFileOpen + process: checks to see if file is currently open + returns true if file pointer not null, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: result of specified test (bool) + Device input/file: none + Device output/monitor: none + Dependencies: accessInputFilePointer + */ + bool checkForInputFileOpen(); + + /* + Name: clearLeadingWhiteSpace + process: captures non printable characters, + and space if flag set, + returns first non white space value found as integer + Function input/parameters: file pointer (FILE *), clear space flag (bool) + Function output/parameters: none + Function output/returned: first non WS character as integer + Device input/file: value captured from file + Device output/monitor: none + Dependencies: fgetc + */ + int clearLeadingWhiteSpace( FILE *filePtr, bool clearSpace ); + + /* + Name: closeInputFile + process: closes input file, returns true if successful, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: none + Device input/file: file closed + Device output/monitor: none + Dependencies: accessInputFilePointer, fclose, accessEndOfInputFileFlag + */ + bool closeInputFile(); + + /* + Name: openInputFile + process: opens input file, sets file pointer and unsets end of file flag, + returns true if successful, false otherwise + Function input/parameters: file name (c-string) + Function output/parameters: none + Function output/returned: success of operation (bool) + Device input/file: file opened + Device output/monitor: none + Dependencies: fopen, accessInputFilePointer, accessEndOfInputFileFlag + */ + bool openInputFile( const char *fileName ); + + /* + Name: readCharacterFromFile + process: ignores leading unprintable characters, including space, + captures first printable character + Function input/parameters: allow space capture (bool) + Function output/parameters: none + Function output/returned: character found if successful, ZERO_CHAR otherwise + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readCharacterFromFileConfigured + */ + char readCharacterFromFile(); + + /* + Name: readCharacterFromFileConfigured + process: ignores leading unprintable characters, + captures first printable character, + including space if allowed + Function input/parameters: allow space capture (bool) + Function output/parameters: none + Function output/returned: character found if successful, ZERO_CHAR otherwise + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, clearLeadingWhiteSpace, + accessEndOfInputFileFlag + */ + char readCharacterFromFileConfigured( bool captureSpace ); + + /* + Name: readDoubleFromFile + process: ignores leading unprintable characters, + captures first contiguous double value + Function input/parameters: none + Function output/parameters: none + Function output/returned: double value found if successful (double) + Device input/file: double value captured from file + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fscanf, accessEndOfInputFileFlag + */ + double readDoubleFromFile(); + + /* + Name: readIntegerFromFile + process: ignores leading unprintable characters, + captures first contiguous integer + Function input/parameters: none + Function output/parameters: none + Function output/returned: integer found if successful, ZERO_VALUE otherwise + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fscanf, accessEndOfInputFileFlag + */ + int readIntegerFromFile(); + + /* + Name: readLongFromFile + process: ignores leading unprintable characters, + captures first contiguous long int + Function input/parameters: none + Function output/parameters: none + Function output/returned: long integer found if successful, + ZERO_VALUE otherwise + Device input/file: long value captured from file + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fscanf, accessEndOfInputFileFlag + */ + long readLongFromFile(); + + /* + Name: readRawCharFromFile + process: captures first character in file stream including non-printable + Function input/parameters: none + Function output/parameters: none + Function output/returned: character found if successful, ZERO_CHAR otherwise + Device input/file: character captured from file + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + accessInputFilePointer, fgetc, accessEndOfInputFileFlag + */ + char readRawCharFromFile(); + + /* + Name: readStringConfiguredFromFile + Process: captures string with options: + - clear leading non printable (bool) + - clear leading space character (bool) + - adquires characters up to any non-printable (bool) + - adquires characters up to any printable delimiter (char) + - use constant NON_PRINTABLE if no delimiter + - also stops capture when full (MAX_STR_LEN) + Note: This function consumes the last character input, + including the space, delimiter, or non-printable character + Function input/parameters: see process above + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: success of operation (bool) + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: checkForInputFileOpen, checkForEndOfInputFile, + clearLeadingWhiteSpace, fgetc, accessEndOfInputFileFlag + */ + bool readStringConfiguredFromFile( bool clearLeadingNonPrintable, + bool clearLeadingSpace, + bool stopAtNonPrintable, + char delimiter, + char *capturedString ); + + /* + Name: readStringSegmentFromFile + process: ignores leading white space, including space character, + captures series of characters up to first space, + or end of line, or full string + Function input/parameters: none + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: success of operation (bool) + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readStringConfigured with appropriate parameters + */ + bool readStringSegmentFromFile( char *capturedString ); + + /* + Name: readStringToLineEndFromFile + process: ignores leading white space, including space character, + captures series of characters up to end of current line + or full string + Function input/parameters: none + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: string found if successful + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readStringConfigured with appropriate parameters + */ + bool readStringToLineEndFromFile( char *capturedString ); + + /* + Name: readStringToDelimiterFromFile + process: ignores leading white space, including space character, + captures series of characters up to specified character + Function input/parameters: none + Function output/parameters: captured string (char *), EMPTY_STRING otherwise + Function output/returned: string found if successful + Device input/file: character(s) captured from file as needed + Device output/monitor: none + Dependencies: readStringConfigured with appropriate parameters + */ + bool readStringToDelimiterFromFile( char delimiter, char *capturedString ); + +#endif // FILE_INPUT_UTILITY_H + diff --git a/PA02-0913/File_Output_Utility.c b/PA02-0913/File_Output_Utility.c new file mode 100644 index 0000000..f982995 --- /dev/null +++ b/PA02-0913/File_Output_Utility.c @@ -0,0 +1,511 @@ +/* +Formatted file ouput utility, function implementations + +Copyright (c) 2021 by Michael E. Leverington + +Code is free for use in whole or in part and may be modified for other +non-commercial use as long as the above copyright statement is included. +*/ + +// header files +#include "File_Output_Utility.h" + +// local global constants, used only in this file + + // dummy file pointer for accessInputFilePointer + const FILE *DUMMY_OUTPUT_FILE_PTR = NULL; + + // dummy Boolean for accessEndOfInputFileFlag, accessOpenFlag +// const char DUMMY_OUTPUT_FLAG = false; + + // control code for accessing file pointer, accessInputFilePointer + const int GET_OUTPUT_FILE_PTR = 6006; + + // control code for accessing flag value, + // accessEndOfInputFileFlag, accessOpenFlag + const int GET_OUTPUT_FLAG = 9009; + + // control code for setting file pointer, accessInputFilePointer + const int SET_OUTPUT_FILE_PTR = 8008; + + // control code for setting flag value, accessEndOfInputFileFlag, + // accessOpenFlag +// const int SET_OUTPUT_FLAG = 1001; + + /* + Name: accessOutputFilePointer + process: allows setting or accessing file pointer; + note: pointer is maintained (static) value initialized to NULL + Function input/parameters: control code (int), file pointer (FILE *) + DUMMY_OUTPUT_FILE_PTR used + if not setting file pointer + Function output/parameters: none + Function output/returned: file pointer (FILE *) + Device input/file: none + Device output/monitor: none + Dependencies: none + */ + FILE *accessOutputFilePointer( int ctrlCode, const FILE *filePtr ) + { + static FILE *filePointer = NULL; + + // check for set new pointer + if( ctrlCode == SET_OUTPUT_FILE_PTR ) + { + // set file pointer to parameter + filePointer = (FILE *)filePtr; + } + + // return file pointer + return filePointer; + } + + /* + Name: closeOutputFile + Process: closes output file, returns true if successful, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: output file closed + Dependencies: accessOutputFilePointer, fclose + */ + bool closeOutputFile() + { + // set local file pointer to working file pointer + // function: accessOutputFilePointer + FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR, + DUMMY_OUTPUT_FILE_PTR ); + + // check for valid file pointer + if( filePtr != NULL ) + { + // add two more endlines to verify that the data is ended + // and has at least one extra newline after the data + // function: fprintf + fprintf( filePtr, "\n\n" ); + + // flush all data to the device + // function: fflush + fflush( filePtr ); + + // close file + // function: fclose + fclose( filePtr ); + + // set pointer to NULL + // function: accessOutputFilePointer + accessOutputFilePointer( SET_OUTPUT_FILE_PTR, NULL ); + + // return successful operation + return true; + } + + // return failed operation + return false; + } + + /* + Name: openOutputFile + Process: opens input file, returns true if successful, false otherwise + Function input/parameters: file name (c-string) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: output file opened + Dependencies: accessOutputFilePointer, fopen + */ + bool openOutputFile( const char *fileName ) + { + // initialize variables + FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR, + DUMMY_OUTPUT_FILE_PTR ); + char writeCharacter[] = "w"; + + // check for file not open + if( filePtr == NULL ) + { + // open file + // function: fopen + filePtr = fopen( fileName, writeCharacter ); + + // check for success of file open + if( filePtr != NULL ) + { + // set pointer in access function + // function: accessInputFilePointer + accessOutputFilePointer( SET_OUTPUT_FILE_PTR, filePtr ); + + // return operation success + return true; + } + } + // end of file not previously opened block + + // return operation failure + return false; + } + + /* + Name: writeCharacterToFile + Process: writes individual character to file, + returns true if successful, false otherwise + Function input/parameters: character to output (char) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: character written to file + Dependencies: accessOutputFilePointer, fprintf + */ + bool writeCharacterToFile( char outChar ) + { + // initialize variables, set file pointer + // function: accessOutputFilePointer + FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR, + DUMMY_OUTPUT_FILE_PTR ); + + // check for open file + // function: checkForOutputFileOpen + if( filePtr != NULL ) + { + // write character + // function: fprintf + fprintf( filePtr, "%c", outChar ); + + // return successful operation + return true; + } + + // return failed operation + return false; + } + + /* + Name: writeCharactersToFile + Process: writes multiple characters to file, + returns true if successful, false otherwise + Function input/parameters: number of characters to output (int), + character to output (char) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: multiple characters written to file + Dependencies: writeCharacterToFile + */ + bool writeCharactersToFile( int numChars, char outChar ) + { + // check for number of characters remaining, + if( numChars > 0 ) + { + // write character, check for success + // function: writeChar + if( writeCharacterToFile( outChar ) ) + { + // continue recursion, + // check for downstream success + // function: writeChars + return writeCharactersToFile( numChars - 1, outChar ); + } + + // quit recursion + // return unsuccessful operation - write operation failed + return false; + } + + // return successful operation - all characters have been written + return true; + } + + /* + Name: writeDoubleToFile + Process: writes individual formatted double value to file, + returns true if successful, false otherwise + Function input/parameters: double value to output (double), + number of digits to right of radix point + (precision) (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: double written to file + Dependencies: writeDoubleJustifiedToFile + */ + bool writeDoubleToFile( double outVal, int precision ) + { + // initialize variables, set block size to zero and justified to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // call to justified function + // function: writeDoubleJustifiedToFile + return writeDoubleJustifiedToFile( outVal, precision, + blockSize, justified ); + } + + /* + Name: writeDoubleToFileJustified + Process: writes individual formatted double value to file justified, + returns true if successful, false otherwise + outVal - the double value to be output + precision - number of digits to the right of the radix point + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification + in block (c-string) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: double written to file as specified + Dependencies: sprintf, writeStringJustifiedToFile + */ + bool writeDoubleJustifiedToFile( double outVal, int precision, + int blockSize, const char *justified ) + { + // initialize variables, create temp string for configuration string + char specStr[ MIN_STR_LEN ]; + + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // set configuration string with precision value + // function: sprintf + sprintf( specStr, "%s0.%dlf", "%", precision ); + + // set double to string + // function: sprintf + sprintf( outStr, specStr, outVal ); + + // write as string, return result + // function: writeStringJustified + return writeStringJustifiedToFile( outStr, blockSize, justified ); + } + + /* + Name: writeEndlineToFile + Process: writes newline ('\n') to file, + returns true if successful, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: newline written to file + Dependencies: accessOutputFilePointer, fprintf + */ + bool writeEndlineToFile() + { + // get file pointer, initialize variable + // function: accessOutputFilePointer + FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR, + DUMMY_OUTPUT_FILE_PTR ); + + // check for open file + if( filePtr != NULL ) + { + // print endline to file + // function: fprintf + fprintf( filePtr, "%c", NEWLINE_CHAR ); + + // return successful operation + return true; + } + + // file not open, return failed operation + return false; + } + + /* + Name: writeEndlinesToFile + Process: writes multiple carriage return ('\r') + and newline ('\n') pairs to file, + returns true if successful, false otherwise + Function input/parameters: number of endline pairs to write (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: multiple newline characters written to file + Dependencies: writeString + */ + bool writeEndlinesToFile( int numEndlines ) + { + // check for number of characters remaining, + if( numEndlines > 0 ) + { + // write endline, check for success + // function: writeEndlineTofile + if( writeEndlineToFile() ) + { + // continue recursion, + // check for downstream success + // function: writeEndlinesToFile + return writeEndlinesToFile( numEndlines - 1 ); + } + + // quit recursion + // return unsuccessful operation - write operation failed + return false; + } + + // return successful operation - all endlines have been written + return true; + } + + /* + Name: writeIntegerToFile + Process: writes individual integer to file, + returns true if successful, false otherwise + Function input/parameters: integer to output (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: integer written to file + Dependencies: writeIntegerJustifiedToFile + */ + bool writeIntegerToFile( int outVal ) + { + // initialize variables, set block size to zero and justified to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // call to justified function + // function: writeDoubleJustifiedToFile + return writeIntegerJustifiedToFile( outVal, blockSize, justified ); + } + + /* + Name: writeIntegerJustifiedToFile + Process: writes individual integer to file, + returns true if successful, false otherwise + Function input/parameters: + outVal - the integer value to be output + precision - number of digits to the right of the radix point + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification + in block (c-string) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: integer written to file as specified + Dependencies: sprintf, writeStringJustifiedToFile + */ + bool writeIntegerJustifiedToFile( int outVal, int blockSize, + const char *justified ) + { + // initialize variables, create temporary output string + char outStr[ MIN_STR_LEN ]; + + // set integer to string + // function: sprintf + sprintf( outStr, "%d", outVal ); + + // write as string, return result + // function: writeStringJustified + return writeStringJustifiedToFile( outStr, blockSize, justified ); + } + + /* + Name: writeStringToFile + Process: writes String value to file, + returns true if successful, false otherwise + Function input/parameters: double value to output (double), + number of digits to right of radix point + (precision) (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: String written to file + Dependencies: writeStringJustifiedToFile + */ + bool writeStringToFile( const char *outString ) + { + // initialize variables, set block size to zero and justified to "LEFT" + int blockSize = 0; + char justified[] = "LEFT"; + + // call to justified function + // function: writeStringJustifiedToFile + return writeStringJustifiedToFile( outString, blockSize, justified ); + } + + /* + Name: writeStringJustifiedToFile + Process: write string to file within specified block size + and with specified justification + Function input/parameters: + outVal - the string value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification + in block (c-string) + Function output/parameters: None + Function output/returned: success of output operation (bool) + Function input/keyboard: None + Device output/file: string written to file as specified + Dependencies: strlen, strcmp, writeCharactersToFile, fprint + */ + bool writeStringJustifiedToFile( const char *outStr, + int blockSize, const char *justify ) + { + // initialize variables, set pre-, post- spaces to zero + int preSpaces = 0, postSpaces = 0, strLength; + + // get file pointer + // function: accessFileOutputFilePointer + FILE *filePtr = accessOutputFilePointer( GET_OUTPUT_FILE_PTR, + DUMMY_OUTPUT_FILE_PTR ); + + if( filePtr != NULL ) + { + // find length of string + // function: strlen + strLength = strlen( outStr ); + + // check justification for "LEFT" + // function: strcmp + if( strcmp( justify, "LEFT" ) == 0 ) + { + // set post spaces for left justification + postSpaces = blockSize - strLength; + } + + // otherwise, check justification for "RIGHT" + // function: strcmp + else if( strcmp( justify, "RIGHT" ) == 0 ) + { + // set pre spaces for right justification + preSpaces = blockSize - strLength; + } + + // Otherwise, assume "CENTER" justification + else + { + // set pre spaces for centered + preSpaces = blockSize / 2 - strLength / 2; + + // set post spaces for centered + postSpaces = blockSize - strLength - preSpaces; + } + + // print pre spaces, check for success + // function: writeCharactersToFile + writeCharactersToFile( preSpaces, SPACE ); + + // print string + // function: fprintf + fprintf( filePtr, "%s", outStr ); + + // print post spaces + // function: printChars + writeCharactersToFile( postSpaces, SPACE ); + + // return successful operation + return true; + } + + // return failed operation + return false; + } + + + + + diff --git a/PA02-0913/File_Output_Utility.h b/PA02-0913/File_Output_Utility.h new file mode 100644 index 0000000..cf06d34 --- /dev/null +++ b/PA02-0913/File_Output_Utility.h @@ -0,0 +1,236 @@ +/* +Formatted file output utility, function prototypes + +Copyright (c) 2021 by Michael E. Leverington + +Code is free for use in whole or in part and may be modified for other +non-commercial use as long as the above copyright statement is included. +*/ +/* +Rev 0.0: 30 June 2021, Initial creation of file + +UTILITY USAGE INSTRUCTIONS: + +1) This utility contains functions that may be used for file input operations + using the C programming language with text files. + The utility must be linked with the program code with which + it will be used. + +2) Specifications for all the functions + are provided in a standardized format below. + +3) Use this code at your own risk. There is no guarantee of any performance, + implied or otherwise, for any part of this code + + END OF INSTRUCTIONS +*/ + +// PreProcessor directives +#ifndef FILE_OUTPUT_UTILITY_H +#define FILE_OUTPUT_UTILITY_H + +// header files +#include +#include +#include +#include "StandardConstants.h" + +// function prototypes + + /* + Name: accessOutputFilePointer + process: allows setting or accessing file pointer; + note: pointer is maintained (static) value initialized to NULL + Function input/parameters: control code (int), file pointer (FILE *) + DUMMY_OUTPUT_FILE_PTR used + if not setting file pointer + Function output/parameters: none + Function output/returned: file pointer (FILE *) + Device input/file: none + Device output/monitor: none + Dependencies: none + */ + FILE *accessOutputFilePointer( int ctrlCode, const FILE *filePtr ); + + /* + Name: closeOutputFile + Process: closes output file, returns true if successful, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: output file closed + Dependencies: accessOutputFilePointer, fclose + */ + bool closeOutputFile(); + + /* + Name: openOutputFile + Process: opens input file, returns true if successful, false otherwise + Function input/parameters: file name (c-string) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: output file opened + Dependencies: accessOutputFilePointer, fopen + */ + bool openOutputFile( const char *fileName ); + + /* + Name: writeCharacterToFile + Process: writes individual character to file, + returns true if successful, false otherwise + Function input/parameters: character to output (char) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: character written to file + Dependencies: accessOutputFilePointer, fprintf + */ + bool writeCharacterToFile( char outChar ); + + /* + Name: writeCharactersToFile + Process: writes multiple characters to file, + returns true if successful, false otherwise + Function input/parameters: number of characters to output (int), + character to output (char) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: multiple characters written to file + Dependencies: writeCharacterToFile + */ + bool writeCharactersToFile( int numChars, char outChar ); + + /* + Name: writeDoubleToFile + Process: writes individual formatted double value to file, + returns true if successful, false otherwise + Function input/parameters: double value to output (double), + number of digits to right of radix point + (precision) (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: double written to file + Dependencies: writeDoubleJustifiedToFile + */ + bool writeDoubleToFile( double outVal, int precision ); + + /* + Name: writeDoubleToFileJustified + Process: writes individual formatted double value to file justified, + returns true if successful, false otherwise + outVal - the double value to be output + precision - number of digits to the right of the radix point + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification + in block (c-string) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: double written to file as specified + Dependencies: sprintf, writeStringJustifiedToFile + */ + bool writeDoubleJustifiedToFile( double outVal, int precision, + int blockSize, const char *justified ); + + /* + Name: writeEndlineToFile + Process: writes newline ('\n') to file, + returns true if successful, false otherwise + Function input/parameters: none + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: newline written to file + Dependencies: accessOutputFilePointer, fprintf + */ + bool writeEndlineToFile(); + + /* + Name: writeEndlinesToFile + Process: writes multiple carriage return ('\r') + and newline ('\n') pairs to file, + returns true if successful, false otherwise + Function input/parameters: number of endline pairs to write (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: multiple newline characters written to file + Dependencies: writeString + */ + bool writeEndlinesToFile( int numEndlines ); + + /* + Name: writeIntegerToFile + Process: writes individual integer to file, + returns true if successful, false otherwise + Function input/parameters: integer to output (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: integer written to file + Dependencies: writeIntegerJustifiedToFile + */ + bool writeIntegerToFile( int outVal ); + + /* + Name: writeIntegerJustifiedToFile + Process: writes individual integer to file, + returns true if successful, false otherwise + Function input/parameters: + outVal - the integer value to be output + precision - number of digits to the right of the radix point + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification + in block (c-string) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: integer written to file as specified + Dependencies: sprintf, writeStringJustifiedToFile + */ + bool writeIntegerJustifiedToFile( int outVal, int blockSize, + const char *justified ); + + /* + Name: writeStringToFile + Process: writes String value to file, + returns true if successful, false otherwise + Function input/parameters: double value to output (double), + number of digits to right of radix point + (precision) (int) + Function output/parameters: none + Function output/returned: operation success (bool) + Device input/file: none + Device output/file: String written to file + Dependencies: writeStringJustifiedToFile + */ + bool writeStringToFile( const char *outString ); + + /* + Name: writeStringJustifiedToFile + Process: write string to file within specified block size + and with specified justification + Function input/parameters: + outVal - the string value to be output + blockSize - the width of the block within which + to print the integer value (int) + justify - "LEFT," "RIGHT," or "CENTER" justification + in block (c-string) + Function output/parameters: None + Function output/returned: success of output operation (bool) + Function input/keyboard: None + Device output/file: string written to file as specified + Dependencies: strlen, strcmp, writeCharactersToFile, fprint + */ + bool writeStringJustifiedToFile( const char *outStr, + int blockSize, const char *justify ); + + +#endif // FILE_OUTPUT_UTILITY_H + diff --git a/PA02-0913/Makefile b/PA02-0913/Makefile new file mode 100644 index 0000000..b806f02 --- /dev/null +++ b/PA02-0913/Makefile @@ -0,0 +1,32 @@ +CC = gcc -Wall +SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c +OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o + +all: PA01_Main + +PA01_Main: $(OBJECTS) + $(CC) $(OBJECTS) -o PA01_Main + +PA01_Main.o: PA01_Main.c + $(CC) -c PA01_Main.c -o PA01_Main.o + +EncryptionUtility.o: EncryptionUtility.c + $(CC) -c EncryptionUtility.c -o EncryptionUtility.o + +Console_IO_Utility.o: Console_IO_Utility.c + $(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o + +File_Input_Utility.o: File_Input_Utility.c + $(CC) -c File_Input_Utility.c -o File_Input_Utility.o + +File_Output_Utility.o: File_Output_Utility.c + $(CC) -c File_Output_Utility.c -o File_Output_Utility.o + +clean: + rm -f $(OBJECTS) PA01_Main PA01_Main.out + +clean_objects: + rm -f $(OBJECTS) + +run: + ./PA01_Main \ No newline at end of file diff --git a/PA02-0913/Makefile_Win b/PA02-0913/Makefile_Win new file mode 100644 index 0000000..8d07827 --- /dev/null +++ b/PA02-0913/Makefile_Win @@ -0,0 +1,29 @@ +CC = gcc -Wall +SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c +OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o + +all: PA01_Main + +PA01_Main: $(OBJECTS) + $(CC) $(OBJECTS) -o PA01_Main.exe + +PA01_Main.o: PA01_Main.c + $(CC) -c PA01_Main.c -o PA01_Main.o + +EncryptionUtility.o: EncryptionUtility.c + $(CC) -c EncryptionUtility.c -o EncryptionUtility.o + +Console_IO_Utility.o: Console_IO_Utility.c + $(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o + +File_Input_Utility.o: File_Input_Utility.c + $(CC) -c File_Input_Utility.c -o File_Input_Utility.o + +File_Output_Utility.o: File_Output_Utility.c + $(CC) -c File_Output_Utility.c -o File_Output_Utility.o + +clean: + del /F $(OBJECTS) PA01_Main PA01_Main.out + +clean_objects: + del /F $(OBJECTS) diff --git a/PA02-0913/PA02_Main.c b/PA02-0913/PA02_Main.c new file mode 100644 index 0000000..04c5d7d --- /dev/null +++ b/PA02-0913/PA02_Main.c @@ -0,0 +1,120 @@ +// header file +#include "Console_IO_Utility.h" +#include "StateUtilities.h" + +// local constants for program +const int MAX_NUM_STATES = 50; + +int main() + { + // initialize function/program + + // initialize variables + int wkgNumStates, sortingNumStates; + int capacity = MAX_NUM_STATES; + char fileName[ MIN_STR_LEN ]; + StateDataType *wkgArray, *sortingArray; + StateDataType resultData, searchData, removeData; + + // show title + // function: showTitle + showTitle(); + + // create input/working and sorting arrays + wkgArray = createStateArray( MAX_NUM_STATES ); + sortingArray = createStateArray( MAX_NUM_STATES ); + + // set empty data - data items will only have the state name + setEmptyElementData( &searchData ); + strcpy( searchData.name, "North Dakota" ); + + setEmptyElementData( &removeData ); + strcpy( removeData.name, "Wyoming" ); + + // get input + + // get file name + // function: getFileName + promptForString( "Enter file name: ", fileName ); + + // upload state data + // function: uploadstateData + wkgNumStates = uploadStateData( wkgArray, capacity, fileName ); + + if( wkgNumStates > 0 ) + { + // make copy of working array for later sorting use + sortingNumStates = wkgNumStates; + copyArray( sortingArray, wkgArray, sortingNumStates ); + + // process and display data + + // display original list + displayData( wkgArray, wkgNumStates, "Original data after upload" ); + + // find state + printf( "\nFinding state: %s\n", searchData.name ); + findStateByName( &resultData, wkgArray, wkgNumStates, searchData ); + printf( "State found: %s, %d, %5.2f%%, %c\n", resultData.name, + 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 ); + + // display bubble-sorted list + displayData( sortingArray, sortingNumStates, + "Full list sorted by name using bubble sort" ); + + // insertion sort + // function: runInsertionSort + runInsertionSortByPopulation( sortingArray, sortingNumStates ); + + // display insertion-sorted list + displayData( sortingArray, sortingNumStates, + "Full list sorted by population using insertion sort" ); + + // selection sort + // function: runSelectionSort + runSelectionSortByGrowth( sortingArray, sortingNumStates ); + + // display insertion-sorted list + displayData( sortingArray, sortingNumStates, + "Full list sorted by growth using selection sort" ); + } + + else + { + printf( "\nData upload failed - program aborted\n" ); + } + + // end program + + // report end program + // function: printf + printf( "\nProgram End\n" ); + + // clear dynamic array + wkgArray = clearStateArray( wkgArray ); + sortingArray = clearStateArray( sortingArray ); + + // return program success + return 0; + } + + diff --git a/PA02-0913/StandardConstants.h b/PA02-0913/StandardConstants.h new file mode 100644 index 0000000..e536c24 --- /dev/null +++ b/PA02-0913/StandardConstants.h @@ -0,0 +1,73 @@ +// Preprocessor directives +#ifndef STANDARD_CONSTANTS_H +#define STANDARD_CONSTANTS_H + +// Include Boolean +#include + +// global constants + +// constant for end of c-string null character +#define CARRIAGE_RETURN_CHAR '\r' + +//constant for a COLON +#define COLON ':' + +//constant for a COMMA +#define COMMA ',' + +//Constant to print a dash +#define DASH '-' + +// highest printable character +#define HIGHEST_PRINTABLE_CHAR '~' + +// constant for huge string length +#define HUGE_STR_LEN 256 + +// lowest printable character +#define LOWEST_PRINTABLE_CHAR ' ' + +// constant for small string length +#define MIN_STR_LEN 32 + +// constant for maximum string length +#define MAX_STR_LEN 128 + +// constant for end of c-string null character +#define NEWLINE_CHAR '\n' + +// first non-printable above ASCII +#define DELETE_KEY 127 + +// constant for end of c-string null character +#define NULL_CHAR '\0' + +// columns found in grade sheet before grading columns +#define NUM_BASE_COLS 5 + +// constant for number of grading frequency bins +#define NUM_FREQUENCY_BINS 10 + +//Constant for printing a pipe +#define PIPE '|' + +//Constant for a period +#define PERIOD '.' + +//Constant for PRECISION, 2 digits +#define PRECISION_2 2 + +//Constant for PRECISION, 4 digits +#define PRECISION_4 4 + +// constant for space character +#define SPACE ' ' + +// constant for standard string length +#define STD_STR_LEN 64 + +// constant for smallest string length +#define TINY_STR_LEN 16 + +#endif // STANDARD_CONSTANTS diff --git a/PA02-0913/StateUtilities.c b/PA02-0913/StateUtilities.c new file mode 100644 index 0000000..e69de29 diff --git a/PA02-0913/StateUtilities.h b/PA02-0913/StateUtilities.h new file mode 100644 index 0000000..7a1d631 --- /dev/null +++ b/PA02-0913/StateUtilities.h @@ -0,0 +1,263 @@ +#ifndef STATE_UTILITIES_H +#define STATE_UTILITIES_H + +// header files +#include +#include +#include +#include "Console_IO_Utility.h" +#include "File_Input_Utility.h" +#include "StandardConstants.h" + +// global constants + +// data structure +typedef struct StateDataStruct + { + char name[ STD_STR_LEN ]; + + int population; + + double growth; + + char majority; + } StateDataType; + +// Prototypes + +/* +Name: addElementFromData +Process: adds all individual data values to StateDataType array + if capacity has not been exceeded, + returns true upon success, false otherwise +Function input/parameters: data array (StateDataType *), + size (int), capacity (int), + state name (const char *), + state population (int), + state growth (double), + state political majority (char) +Function output/parameters: updated data array (StateDataType *), + updated size (int *) +Function output/returned: Boolean result of operation as specified +Device input/---: none +Device output/---: none +Dependencies: as needed, including strcpy +*/ +bool addElementFromData( StateDataType *stateArr, int *size, int capacity, + const char *stateName, int statePop, + double stateGrowth, char politicalMajority ); + +/* +Name: addElementFromElement +Process: adds data from element to StateDataType array, + uses supporting function +Function input/parameters: data array (StateDataType *), + size and capacity (int), + source element (const StateDataType) +Function output/parameters: updated data array (StateDataType *), + updated size (int *) +Function output/returned: Boolean result of operation as specified +Device input/---: none +Device output/---: none +Dependencies: addElementFromData - function uses one code statement +*/ +bool addElementFromElement( StateDataType *stateArr, int *size, int capacity, + const StateDataType state ); + +/* +Name: clearStateArray +Process: deallocates dynamically allocated array from memory +Function input/parameters: data array (StateDataType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: as needed, including free +*/ +StateDataType *clearStateArray( StateDataType *array ); + +/* +Name: copyArray +Process: copies state data elements from one array to another +Function input/parameters: source array (const StateDataType *), size (int) +Function output/parameters: pointer to destination array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void copyArray( StateDataType *dest, const StateDataType *src, int srcSize ); + +/* +Name: createStateArray +Process: dynamically allocates array memory +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to newly created array (StateDataType *) +Device input/---: none +Device output/---: none +Dependencies: as needed, including function malloc and keyword sizeof +*/ +StateDataType *createStateArray( int initialCapacity ); + +/* +Name: deepCopy +Process: copies all individual values from StateDataType source + to StateDataType destination +Function input/parameters: source element (const StateDataType) +Function output/parameters: pointer to destination value (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed, including strcpy +*/ +void deepCopy( StateDataType *dest, const StateDataType src ); + +/* +Name: displayData +Process: displays element data in array as table if array is not empty, + otherwise displays "Data not found - Display aborted", + allows for subtitle to be added to "Display Data - " +Function input/parameters: state data array (const StateDataType *), + size (int), subtitle (const char *) +Function output/parameters: none +Function output/returned: none +Device input/---: none +Device output/monitor: data displayed as specified +Dependencies: as needed +*/ +void displayData( const StateDataType *array, int size, const char *subTitle ); + +/* +Name: findStateByName +Process: finds element value in array by state name if it exists in the array, + saves data in return parameter and returns true, + otherwise sets data in return parameter to empty and returns false +Function input/parameters: state data array (const StateDataType *), + size (int), search value (const StateDataType) +Function output/parameters: value if found as return parameter, + otherwise, return parameter set to empty + (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +bool findStateByName( StateDataType *foundElement, + const StateDataType *array, int size, const StateDataType searchValue ); + +/* +Name: removeStateByName +Process: searches for element, if found, sets data into return parameter, + shifts all remaining data down, and returns true, + otherwise sets data in return parameter to empty and returns false +Function input/parameters: state data array (StateDataType *), + size (int), search value (const StateDataType) +Function output/parameters: updated state data array (StateDataType *), + value if found and removed, + otherwise, value set to empty (StateDataType *), + updated size (int *) +Function output/returned: Boolean result of operation as specified +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +bool removeStateByName( StateDataType *removedElement, + StateDataType *array, int *size, const StateDataType searchVal ); + +/* +Name: runBubbleSortByName +Process: sorts state data by name using bubble sort algorithm +Function input/parameters: state data array (StateDataType *), size (int) +Function output/parameters: updated state data array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void runBubbleSortByName( StateDataType *array, int size ); + +/* +Name: runInsertionSortByPopulation +Process: sorts state data by population using insertion sort algorithm +Function input/parameters: state data array (StateDataType *), size (int) +Function output/parameters: updated state data array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed, swap may not be used +*/ +void runInsertionSortByPopulation( StateDataType *array, int size ); + +/* +Name: runSelectionSortByGrowth +Process: sorts state data by growth using selection sort algorithm +Function input/parameters: state data array (StateDataType *), size (int) +Function output/parameters: updated state data array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void runSelectionSortByGrowth( StateDataType *array, int size ); + +/* +Name: setEmptyElementData +Process: sets state data type to empty or default values, + name to empty string, population and growth to zero, + and majority to 'x' +Function input/parameters: none +Function output/parameters: state data value (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: none +*/ +void setEmptyElementData( StateDataType *element ); + +/* +Name: showTitle +Process: displays program title with thick underline, + "Data Management with N-Squared Sorting" +Function input/parameters: none +Function output/parameters: none +Function output/returned: none +Device input/---: none +Device output/monitor: displays title as specified +Dependencies: as needed +*/ +void showTitle(); + +/* +Name: swapElements +Process: swaps state data elements within an array +Function input/parameters: given array (StateDataType *), + left and right indices to be swapped (int) +Function output/parameters: updated array with swapped values (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void swapElements( StateDataType *array, int leftIndex, int rightIndex ); + +/* +Name: uploadStateData +Process: uploads data from given file to state data array, + ignores first (title) line in .csv file, + then captures comma-delimited state name, population, growth, + and political majority data on each row, + returns number of items found; + stops uploading process if array is full +Function input/parameters: capacity (int) and file name (const char *) +Function output/parameters: updated array with uploaded values (StateDataType *) +Function output/returned: number of items uploaded (int) +Device input/HD: data uploaded from text file as specified +Device output/---: none +Dependencies: as needed +*/ +int uploadStateData( StateDataType *StateDataArray, + int capacity, const char *fileName ); + +#endif // STATE_UTILITIES_H + From 91b6fc42d5992e4eec738ae686a1c6294145fbc8 Mon Sep 17 00:00:00 2001 From: cdez Date: Tue, 5 Sep 2023 23:48:51 -0700 Subject: [PATCH 10/10] Initialized STUB Functions, Refined Make ++ PA02 STUB functions/StateUtilities.c -- Makefile_Win (No longer required since refined for Windows/UNIX) --- PA02-0913/Makefile | 25 ++-- PA02-0913/Makefile_Win | 29 ---- PA02-0913/StateUtilities.c | 297 +++++++++++++++++++++++++++++++++++++ 3 files changed, 311 insertions(+), 40 deletions(-) delete mode 100644 PA02-0913/Makefile_Win diff --git a/PA02-0913/Makefile b/PA02-0913/Makefile index b806f02..133be4b 100644 --- a/PA02-0913/Makefile +++ b/PA02-0913/Makefile @@ -1,17 +1,17 @@ CC = gcc -Wall -SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c -OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o +SOURCES = PA02_Main.c StateUtilities.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c +OBJECTS = PA02_Main.o StateUtilities.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o -all: PA01_Main +all: PA02_Main -PA01_Main: $(OBJECTS) - $(CC) $(OBJECTS) -o PA01_Main +PA02_Main: $(OBJECTS) + $(CC) $(OBJECTS) -o PA02_Main -PA01_Main.o: PA01_Main.c - $(CC) -c PA01_Main.c -o PA01_Main.o +PA02_Main.o: PA02_Main.c + $(CC) -c PA02_Main.c -o PA02_Main.o -EncryptionUtility.o: EncryptionUtility.c - $(CC) -c EncryptionUtility.c -o EncryptionUtility.o +StateUtilities.o: StateUtilities.c + $(CC) -c StateUtilities.c -o StateUtilities.o Console_IO_Utility.o: Console_IO_Utility.c $(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o @@ -23,10 +23,13 @@ File_Output_Utility.o: File_Output_Utility.c $(CC) -c File_Output_Utility.c -o File_Output_Utility.o clean: - rm -f $(OBJECTS) PA01_Main PA01_Main.out + rm -f $(OBJECTS) PA02_Main PA02_Main.out clean_objects: rm -f $(OBJECTS) run: - ./PA01_Main \ No newline at end of file + ./PA02_Main + +run_win: + PA02_Main \ No newline at end of file diff --git a/PA02-0913/Makefile_Win b/PA02-0913/Makefile_Win deleted file mode 100644 index 8d07827..0000000 --- a/PA02-0913/Makefile_Win +++ /dev/null @@ -1,29 +0,0 @@ -CC = gcc -Wall -SOURCES = PA01_Main.c EncryptionUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c -OBJECTS = PA01_Main.o EncryptionUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o - -all: PA01_Main - -PA01_Main: $(OBJECTS) - $(CC) $(OBJECTS) -o PA01_Main.exe - -PA01_Main.o: PA01_Main.c - $(CC) -c PA01_Main.c -o PA01_Main.o - -EncryptionUtility.o: EncryptionUtility.c - $(CC) -c EncryptionUtility.c -o EncryptionUtility.o - -Console_IO_Utility.o: Console_IO_Utility.c - $(CC) -c Console_IO_Utility.c -o Console_IO_Utility.o - -File_Input_Utility.o: File_Input_Utility.c - $(CC) -c File_Input_Utility.c -o File_Input_Utility.o - -File_Output_Utility.o: File_Output_Utility.c - $(CC) -c File_Output_Utility.c -o File_Output_Utility.o - -clean: - del /F $(OBJECTS) PA01_Main PA01_Main.out - -clean_objects: - del /F $(OBJECTS) diff --git a/PA02-0913/StateUtilities.c b/PA02-0913/StateUtilities.c index e69de29..82bb305 100644 --- a/PA02-0913/StateUtilities.c +++ b/PA02-0913/StateUtilities.c @@ -0,0 +1,297 @@ +#include "StateUtilities.h" + +// local constants +const int NAME_BLOCK_SIZE = 16; +const int POPULATION_BLOCK_SIZE = 12; +const int GROWTH_BLOCK_SIZE = 10; + +// functions + +/* +Name: addElementFromData +Process: adds all individual data values to StateDataType array + if capacity has not been exceeded, + returns true upon success, false otherwise +Function input/parameters: data array (StateDataType *), + size (int), capacity (int), + state name (const char *), + state population (int), + state growth (double), + state political majority (char) +Function output/parameters: updated data array (StateDataType *), + updated size (int *) +Function output/returned: Boolean result of operation as specified +Device input/---: none +Device output/---: none +Dependencies: as needed, including strcpy +*/ +bool addElementFromData( StateDataType *stateArr, int *size, int capacity, + const char *stateName, int statePop, + double stateGrowth, char politicalMajority ) +{ + // + return NULL; +} + +/* +Name: addElementFromElement +Process: adds data from element to StateDataType array, + uses supporting function +Function input/parameters: data array (StateDataType *), + size and capacity (int), + source element (const StateDataType) +Function output/parameters: updated data array (StateDataType *), + updated size (int *) +Function output/returned: Boolean result of operation as specified +Device input/---: none +Device output/---: none +Dependencies: addElementFromData - function uses one code statement +*/ +bool addElementFromElement( StateDataType *stateArr, int *size, int capacity, + const StateDataType state ) +{ + // + return NULL; +} + +/* +Name: clearStateArray +Process: deallocates dynamically allocated array from memory +Function input/parameters: data array (StateDataType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: as needed, including free +*/ +StateDataType *clearStateArray( StateDataType *array ) +{ + // + return NULL; +} + +/* +Name: copyArray +Process: copies state data elements from one array to another +Function input/parameters: source array (const StateDataType *), size (int) +Function output/parameters: pointer to destination array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void copyArray( StateDataType *dest, const StateDataType *src, int srcSize ) +{ + // no return, void +} + +/* +Name: createStateArray +Process: dynamically allocates array memory +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to newly created array (StateDataType *) +Device input/---: none +Device output/---: none +Dependencies: as needed, including function malloc and keyword sizeof +*/ +StateDataType *createStateArray( int initialCapacity ) +{ + // + return NULL; +} + +/* +Name: deepCopy +Process: copies all individual values from StateDataType source + to StateDataType destination +Function input/parameters: source element (const StateDataType) +Function output/parameters: pointer to destination value (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed, including strcpy +*/ +void deepCopy( StateDataType *dest, const StateDataType src ) +{ + // no return, void +} + +/* +Name: displayData +Process: displays element data in array as table if array is not empty, + otherwise displays "Data not found - Display aborted", + allows for subtitle to be added to "Display Data - " +Function input/parameters: state data array (const StateDataType *), + size (int), subtitle (const char *) +Function output/parameters: none +Function output/returned: none +Device input/---: none +Device output/monitor: data displayed as specified +Dependencies: as needed +*/ +void displayData( const StateDataType *array, int size, const char *subTitle ) +{ + // no return, void +} + +/* +Name: findStateByName +Process: finds element value in array by state name if it exists in the array, + saves data in return parameter and returns true, + otherwise sets data in return parameter to empty and returns false +Function input/parameters: state data array (const StateDataType *), + size (int), search value (const StateDataType) +Function output/parameters: value if found as return parameter, + otherwise, return parameter set to empty + (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +bool findStateByName( StateDataType *foundElement, + const StateDataType *array, int size, const StateDataType searchValue ) +{ + // + return NULL; +} + +/* +Name: removeStateByName +Process: searches for element, if found, sets data into return parameter, + shifts all remaining data down, and returns true, + otherwise sets data in return parameter to empty and returns false +Function input/parameters: state data array (StateDataType *), + size (int), search value (const StateDataType) +Function output/parameters: updated state data array (StateDataType *), + value if found and removed, + otherwise, value set to empty (StateDataType *), + updated size (int *) +Function output/returned: Boolean result of operation as specified +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +bool removeStateByName( StateDataType *removedElement, + StateDataType *array, int *size, const StateDataType searchVal ) +{ + // + return NULL; +} + +/* +Name: runBubbleSortByName +Process: sorts state data by name using bubble sort algorithm +Function input/parameters: state data array (StateDataType *), size (int) +Function output/parameters: updated state data array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void runBubbleSortByName( StateDataType *array, int size ) +{ + // no return, void +} + +/* +Name: runInsertionSortByPopulation +Process: sorts state data by population using insertion sort algorithm +Function input/parameters: state data array (StateDataType *), size (int) +Function output/parameters: updated state data array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed, swap may not be used +*/ +void runInsertionSortByPopulation( StateDataType *array, int size ) +{ + // no return, void +} + +/* +Name: runSelectionSortByGrowth +Process: sorts state data by growth using selection sort algorithm +Function input/parameters: state data array (StateDataType *), size (int) +Function output/parameters: updated state data array (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void runSelectionSortByGrowth( StateDataType *array, int size ) +{ + // no return, void +} + +/* +Name: setEmptyElementData +Process: sets state data type to empty or default values, + name to empty string, population and growth to zero, + and majority to 'x' +Function input/parameters: none +Function output/parameters: state data value (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: none +*/ +void setEmptyElementData( StateDataType *element ) +{ + // no return, void +} + +/* +Name: showTitle +Process: displays program title with thick underline, + "Data Management with N-Squared Sorting" +Function input/parameters: none +Function output/parameters: none +Function output/returned: none +Device input/---: none +Device output/monitor: displays title as specified +Dependencies: as needed +*/ +void showTitle() +{ + // no return, void +} + +/* +Name: swapElements +Process: swaps state data elements within an array +Function input/parameters: given array (StateDataType *), + left and right indices to be swapped (int) +Function output/parameters: updated array with swapped values (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: as needed +*/ +void swapElements( StateDataType *array, int leftIndex, int rightIndex ) +{ + // no return, void +} + +/* +Name: uploadStateData +Process: uploads data from given file to state data array, + ignores first (title) line in .csv file, + then captures comma-delimited state name, population, growth, + and political majority data on each row, + returns number of items found; + stops uploading process if array is full +Function input/parameters: capacity (int) and file name (const char *) +Function output/parameters: updated array with uploaded values (StateDataType *) +Function output/returned: number of items uploaded (int) +Device input/HD: data uploaded from text file as specified +Device output/---: none +Dependencies: as needed +*/ +int uploadStateData( StateDataType *StateDataArray, + int capacity, const char *fileName ) +{ + // + return 0; +} \ No newline at end of file