Initialize PA10, STUB Functions
++ PA10 Files ++ Makefile for PA10
This commit is contained in:
parent
d9e90f6501
commit
91ce50b189
17 changed files with 4154 additions and 0 deletions
590
PA10-1115/Console_IO_Utility.c
Normal file
590
PA10-1115/Console_IO_Utility.c
Normal file
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
289
PA10-1115/Console_IO_Utility.h
Normal file
289
PA10-1115/Console_IO_Utility.h
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
// Preprocessor directive
|
||||
#ifndef CONSOLE_IO_UTILITY_H
|
||||
#define CONSOLE_IO_UTILITY_H
|
||||
|
||||
//Header Files
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
717
PA10-1115/File_Input_Utility.c
Normal file
717
PA10-1115/File_Input_Utility.c
Normal file
|
|
@ -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 <stdlib.h> //////////////////////////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 );
|
||||
}
|
||||
|
||||
|
||||
295
PA10-1115/File_Input_Utility.h
Normal file
295
PA10-1115/File_Input_Utility.h
Normal file
|
|
@ -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 <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#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
|
||||
|
||||
511
PA10-1115/File_Output_Utility.c
Normal file
511
PA10-1115/File_Output_Utility.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
236
PA10-1115/File_Output_Utility.h
Normal file
236
PA10-1115/File_Output_Utility.h
Normal file
|
|
@ -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 <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
|
||||
81
PA10-1115/GeneralUtility.c
Normal file
81
PA10-1115/GeneralUtility.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Header files ///////////////////////////////////////////////////////////////
|
||||
#include "GeneralUtility.h"
|
||||
|
||||
// global constants ////////////////////////////////////////////////////////////
|
||||
|
||||
// none
|
||||
|
||||
// data structures /////////////////////////////////////////////////////////////
|
||||
|
||||
// None
|
||||
|
||||
/*
|
||||
Name: privateCompareStrings
|
||||
Process: compares two strings as follows:
|
||||
- if left string is alphabetically greater than the right string,
|
||||
returns value greater than zero
|
||||
- if left string is alphabetically less than the right string,
|
||||
returns value less than zero
|
||||
- if strings are alphabetically equal but one is longer,
|
||||
longer one is greater
|
||||
- otherwise, returns zero
|
||||
Function input/parameters: two strings to be compared (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result as specified above (int)
|
||||
Device input/ ---: none
|
||||
Device output/ ---: none
|
||||
Dependencies: privateGetStringLength
|
||||
*/
|
||||
int privateCompareStrings( const char *leftStr, const char *rightStr )
|
||||
{
|
||||
// return zero (temp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: privateCopyString
|
||||
Process: copies string character for character up to NULL_CHAR of source string
|
||||
Function input/parameters: source string to be copied (const char *)
|
||||
Function output/parameters: destination string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
void privateCopyString( char *dest, const char *source )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: privateGetStringLength
|
||||
Process: finds length of string
|
||||
Function input/parameters: c-style string (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: calculated length of string (int)
|
||||
Device input/ ---: none
|
||||
Device output/ ---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
int privateGetStringLength( const char *str )
|
||||
{
|
||||
// return zero (temp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: privateToPower
|
||||
Process: recursively calculates result of given base to given exponent,
|
||||
for exponents >= 0
|
||||
Function input/parameters: base and exponent (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified calculations (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: toPower (recursively)
|
||||
*/
|
||||
int privateToPower( int base, int exponent )
|
||||
{
|
||||
// return zero (temp)
|
||||
return 0;
|
||||
}
|
||||
78
PA10-1115/GeneralUtility.h
Normal file
78
PA10-1115/GeneralUtility.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// Precompiler directives /////////////////////////////////////////////////////
|
||||
|
||||
#ifndef GENERAL_UTILITY_H
|
||||
#define GENERAL_UTILITY_H
|
||||
|
||||
// Header files ///////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// global constants ////////////////////////////////////////////////////////////
|
||||
|
||||
// none
|
||||
|
||||
// data structures /////////////////////////////////////////////////////////////
|
||||
|
||||
// None
|
||||
|
||||
/*
|
||||
Name: privateCompareStrings
|
||||
Process: compares two strings as follows:
|
||||
- if left string is alphabetically greater than the right string,
|
||||
returns value greater than zero
|
||||
- if left string is alphabetically less than the right string,
|
||||
returns value less than zero
|
||||
- if strings are alphabetically equal but one is longer,
|
||||
longer one is greater
|
||||
- otherwise, returns zero
|
||||
Function input/parameters: two strings to be compared (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result as specified above (int)
|
||||
Device input/ ---: none
|
||||
Device output/ ---: none
|
||||
Dependencies: privateGetStringLength
|
||||
*/
|
||||
int privateCompareStrings( const char *leftStr, const char *rightStr );
|
||||
|
||||
/*
|
||||
Name: privateCopyString
|
||||
Process: copies string character for character up to NULL_CHAR of source string
|
||||
Function input/parameters: source string to be copied (const char *)
|
||||
Function output/parameters: destination string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
void privateCopyString( char *dest, const char *source );
|
||||
|
||||
/*
|
||||
Name: privateGetStringLength
|
||||
Process: finds length of string
|
||||
Function input/parameters: c-style string (const char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: calculated length of string (int)
|
||||
Device input/ ---: none
|
||||
Device output/ ---: none
|
||||
Dependencies: none
|
||||
*/
|
||||
int privateGetStringLength( const char *str );
|
||||
|
||||
/*
|
||||
Name: privateToPower
|
||||
Process: recursively calculates result of given base to given exponent,
|
||||
for exponents >= 0
|
||||
Function input/parameters: base and exponent (int)
|
||||
Function output/parameters: none
|
||||
Function output/returned: result of specified calculations (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: toPower (recursively)
|
||||
*/
|
||||
int privateToPower( int base, int exponent );
|
||||
|
||||
|
||||
#endif // GENERAL_UTILITY_H
|
||||
|
||||
|
||||
|
||||
209
PA10-1115/HashUtility.c
Normal file
209
PA10-1115/HashUtility.c
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
// header files
|
||||
#include "HashUtility.h"
|
||||
|
||||
// constants
|
||||
|
||||
/*
|
||||
typedef struct HashStruct
|
||||
{
|
||||
StateDataType *array;
|
||||
|
||||
int tableSize;
|
||||
|
||||
ProbeType probeStrategy;
|
||||
} ProbingHashType;
|
||||
*/
|
||||
|
||||
// function definitions
|
||||
|
||||
/*
|
||||
Name: addItemFromData
|
||||
Process: adds item to hash table using data input,
|
||||
sets node to used state
|
||||
Function input/parameters: hash data (ProbingHashType *),
|
||||
state name (const char *),
|
||||
average, lowest, and highest temperatures (double),
|
||||
Function output/parameters: updated hash table data (ProbingHashType *)
|
||||
Function output/returned: result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/monitor: probing process displayed (in called function)
|
||||
Dependencies: setDataNodeFromData, addItemFromStruct
|
||||
*/
|
||||
bool addItemFromData( ProbingHashType *hashTable, const char *stateName,
|
||||
double avgTemp, double lowTemp, double highTemp )
|
||||
{
|
||||
// return false (temp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: addItemFromStruct
|
||||
Process: adds item to hash table using struct input,
|
||||
uses probing as specified in hashTable data,
|
||||
either LINEAR_PROBING or QUADRATIC_PROBING,
|
||||
may probe as many as tableSize times
|
||||
Function input/parameters: hash data (ProbingHashType *),
|
||||
new item (StateDataType)
|
||||
Function output/parameters: updated hash table data (ProbingHashType *)
|
||||
Function output/returned: result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/monitor: probing process displayed
|
||||
Dependencies: getHashIndex, privateToPower, printf, stateDataToString,
|
||||
setDataNodeFromStruct
|
||||
*/
|
||||
bool addItemFromStruct( ProbingHashType *hashTable, StateDataType newItem )
|
||||
{
|
||||
// return false (temp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: clearHashTable
|
||||
Process: clear hash table array, deallocates hash struct
|
||||
Function input/parameters: hash data (ProbingHashType *)
|
||||
Function output/parameters: updated hash table data (ProbingHashType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: free
|
||||
*/
|
||||
void clearHashTable( ProbingHashType *hashTable )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: displayHashTable
|
||||
Process: array data dump of numbered data to screen,
|
||||
shows data where used, shows "Unused" where not
|
||||
Function input/parameters: provided hashTable data (const ProbingHashType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: displayed as specified
|
||||
Dependencies: printf, stateDataToString
|
||||
*/
|
||||
void displayHashTable( const ProbingHashType *hashTable )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: findItem
|
||||
Process: finds item in hash table, returns
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: state data set to struct (StateDataType),
|
||||
or search parameter set to empty node if not found
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: findItemIndex, setEmptyDataNode
|
||||
*/
|
||||
StateDataType findItem( const ProbingHashType *hashTable,
|
||||
StateDataType searchItem )
|
||||
{
|
||||
// return NULL (temp)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: findItemIndex
|
||||
Process: finds item index, using probing strategy provided in hashTable data,
|
||||
otherwise,
|
||||
returns ITEM_NOT_FOUND if search fails after tableSize attempts,
|
||||
displays index probing attempts
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: index or ITEM_NOT_FOUND (int) as specified
|
||||
Device input/---: none
|
||||
Device output/monitor: displays probing action, provided in sample run file
|
||||
Dependencies: getHashIndex, printf, privateCompareStrings, privateToPower,
|
||||
setDataNodeFromStruct
|
||||
*/
|
||||
int findItemIndex( const ProbingHashType *hashTable, StateDataType searchItem )
|
||||
{
|
||||
// return zero (temp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: getHashIndex
|
||||
Process: finds hashed index for given data item,
|
||||
sums integer values of state name characters,
|
||||
if state name length is less than MINIMUM_HASH_LETTER_COUNT,
|
||||
repeats going over the state letters as needed to meet this minimum
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType)
|
||||
Function output/parameters: none
|
||||
Function output/returned: array index generated from state name (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: privateGetStringLength
|
||||
*/
|
||||
int getHashIndex( const ProbingHashType hashTable, const StateDataType state )
|
||||
{
|
||||
// return zero (temp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: initializeHashTable
|
||||
Process: creates dynamically allocated hashTable,
|
||||
creates dynamically allocated array of empty StateDataType items,
|
||||
initializes tableSize to given capacity,
|
||||
initializes probe strategy to given strategy
|
||||
Function input/parameters: provided capacity (int),
|
||||
provided probe strategy (ProbeType)
|
||||
Function output/parameters: none
|
||||
Function output/returned: pointer to created hashTable (ProbingHashType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: malloc, setEmptyDataNode,
|
||||
*/
|
||||
ProbingHashType *initializeHashTable( int capacity, ProbeType probe )
|
||||
{
|
||||
// return NULL (temp)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: removeState
|
||||
Process: finds item in hash table, removes,
|
||||
sets array location to unused (but does not set any other data),
|
||||
returns removed state
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType)
|
||||
Function output/parameters: returned state (StateDataType *)
|
||||
Function output/returned: Boolean result of action (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: findItemIndex, setDataNodeFromStruct
|
||||
*/
|
||||
bool removeState( StateDataType *removedState,
|
||||
const StateDataType toBeRemoved, const ProbingHashType hashTable )
|
||||
{
|
||||
// return false (temp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: showHashTableStatus
|
||||
Process: displays array <D>ata values and <U>unused values
|
||||
as a string of letters,
|
||||
displays number of items in hashTable,
|
||||
displays minimum number of contiguous data items,
|
||||
displays maximum number of contiguous data items,
|
||||
displays number of empty/unused array elements
|
||||
Function input/parameters: hashTable (const ProbingHashType)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: hash data status displayed as specified
|
||||
Dependencies: sprintf, printf
|
||||
*/
|
||||
void showHashTableStatus( const ProbingHashType hashTable)
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
186
PA10-1115/HashUtility.h
Normal file
186
PA10-1115/HashUtility.h
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
#ifndef HASH_UTILITIES_H
|
||||
#define HASH_UTILITIES_H
|
||||
|
||||
// header files
|
||||
#include "StandardConstants.h"
|
||||
#include "GeneralUtility.h"
|
||||
#include "StateDataUtility.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// constants
|
||||
typedef enum { NO_PROBING, LINEAR_PROBING = 101,
|
||||
QUADRATIC_PROBING = 202 } ProbeType;
|
||||
extern const int MINIMUM_HASH_LETTER_COUNT;
|
||||
extern const int ITEM_NOT_FOUND;
|
||||
extern const bool USED_NODE;
|
||||
extern const bool UNUSED_NODE;
|
||||
|
||||
typedef struct HashStruct
|
||||
{
|
||||
StateDataType *array;
|
||||
|
||||
int tableSize;
|
||||
|
||||
ProbeType probeStrategy;
|
||||
} ProbingHashType;
|
||||
|
||||
// prototypes
|
||||
|
||||
/*
|
||||
Name: addItemFromData
|
||||
Process: adds item to hash table using data input,
|
||||
sets node to used state
|
||||
Function input/parameters: hash data (ProbingHashType *),
|
||||
state name (const char *),
|
||||
average, lowest, and highest temperatures (double),
|
||||
Function output/parameters: updated hash table data (ProbingHashType *)
|
||||
Function output/returned: result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/monitor: probing process displayed (in called function)
|
||||
Dependencies: setDataNodeFromData, addItemFromStruct
|
||||
*/
|
||||
bool addItemFromData( ProbingHashType *hashTable, const char *stateName,
|
||||
double avgTemp, double lowTemp, double highTemp );
|
||||
|
||||
/*
|
||||
Name: addItemFromStruct
|
||||
Process: adds item to hash table using struct input,
|
||||
uses probing as specified in hashTable data,
|
||||
either LINEAR_PROBING or QUADRATIC_PROBING,
|
||||
may probe as many as tableSize times
|
||||
Function input/parameters: hash data (ProbingHashType *),
|
||||
new item (StateDataType)
|
||||
Function output/parameters: updated hash table data (ProbingHashType *)
|
||||
Function output/returned: result of operation (bool)
|
||||
Device input/---: none
|
||||
Device output/monitor: probing process displayed
|
||||
Dependencies: getHashIndex, privateToPower, printf, stateDataToString,
|
||||
setDataNodeFromStruct
|
||||
*/
|
||||
bool addItemFromStruct( ProbingHashType *hashTable, StateDataType newItem );
|
||||
|
||||
/*
|
||||
Name: clearHashTable
|
||||
Process: clear hash table array, deallocates hash struct
|
||||
Function input/parameters: hash data (ProbingHashType *)
|
||||
Function output/parameters: updated hash table data (ProbingHashType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: free
|
||||
*/
|
||||
void clearHashTable( ProbingHashType *hashTable );
|
||||
|
||||
/*
|
||||
Name: displayHashTable
|
||||
Process: array data dump of numbered data to screen,
|
||||
shows data where used, shows "Unused" where not
|
||||
Function input/parameters: provided hashTable data (const ProbingHashType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: displayed as specified
|
||||
Dependencies: printf, stateDataToString
|
||||
*/
|
||||
void displayHashTable( const ProbingHashType *hashTable );
|
||||
|
||||
/*
|
||||
Name: findItem
|
||||
Process: finds item in hash table, returns
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: state data set to struct (StateDataType),
|
||||
or search parameter set to empty node if not found
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: findItemIndex, setEmptyDataNode
|
||||
*/
|
||||
StateDataType findItem( const ProbingHashType *hashTable,
|
||||
StateDataType searchItem );
|
||||
|
||||
/*
|
||||
Name: findItemIndex
|
||||
Process: finds item index, using probing strategy provided in hashTable data,
|
||||
otherwise,
|
||||
returns ITEM_NOT_FOUND if search fails after tableSize attempts,
|
||||
displays index probing attempts
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: index or ITEM_NOT_FOUND (int) as specified
|
||||
Device input/---: none
|
||||
Device output/monitor: displays probing action, provided in sample run file
|
||||
Dependencies: getHashIndex, printf, privateCompareStrings, privateToPower,
|
||||
setDataNodeFromStruct
|
||||
*/
|
||||
int findItemIndex( const ProbingHashType *hashTable, StateDataType searchItem );
|
||||
|
||||
/*
|
||||
Name: getHashIndex
|
||||
Process: finds hashed index for given data item,
|
||||
sums integer values of state name characters,
|
||||
if state name length is less than MINIMUM_HASH_LETTER_COUNT,
|
||||
repeats going over the state letters as needed to meet this minimum
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType)
|
||||
Function output/parameters: none
|
||||
Function output/returned: array index generated from state name (int)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: privateGetStringLength
|
||||
*/
|
||||
int getHashIndex( const ProbingHashType hashTable, const StateDataType state );
|
||||
|
||||
/*
|
||||
Name: initializeHashTable
|
||||
Process: creates dynamically allocated hashTable,
|
||||
creates dynamically allocated array of empty StateDataType items,
|
||||
initializes tableSize to given capacity,
|
||||
initializes probe strategy to given strategy
|
||||
Function input/parameters: provided capacity (int),
|
||||
provided probe strategy (ProbeType)
|
||||
Function output/parameters: none
|
||||
Function output/returned: pointer to created hashTable (ProbingHashType *)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: malloc, setEmptyDataNode,
|
||||
*/
|
||||
ProbingHashType *initializeHashTable( int capacity, ProbeType probe );
|
||||
|
||||
/*
|
||||
Name: removeState
|
||||
Process: finds item in hash table, removes,
|
||||
sets array location to unused (but does not set any other data),
|
||||
returns removed state
|
||||
Function input/parameters: provided search data (const StateDataType),
|
||||
hashTable (const ProbingHashType)
|
||||
Function output/parameters: returned state (StateDataType *)
|
||||
Function output/returned: Boolean result of action (bool)
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: findItemIndex, setDataNodeFromStruct
|
||||
*/
|
||||
bool removeState( StateDataType *removedState,
|
||||
const StateDataType toBeRemoved, const ProbingHashType hashTable );
|
||||
|
||||
/*
|
||||
Name: showHashTableStatus
|
||||
Process: displays array <D>ata values and <U>unused values
|
||||
as a string of letters,
|
||||
displays number of items in hashTable,
|
||||
displays minimum number of contiguous data items,
|
||||
displays maximum number of contiguous data items,
|
||||
displays number of empty/unused array elements
|
||||
Function input/parameters: hashTable (const ProbingHashType)
|
||||
Function output/parameters: none
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/monitor: hash data status displayed as specified
|
||||
Dependencies: sprintf, printf
|
||||
*/
|
||||
void showHashTableStatus( const ProbingHashType hashTable);
|
||||
|
||||
|
||||
#endif // HASH_UTILITIES_H
|
||||
43
PA10-1115/Makefile
Normal file
43
PA10-1115/Makefile
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
CC = gcc -Wall
|
||||
SOURCES = PA09_Main.c GeneralUtility.c HeapUtility.c StudentUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c
|
||||
OBJECTS = PA09_Main.o GeneralUtility.o HeapUtility.o StudentUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o
|
||||
|
||||
# Uses the template structure defined in the TypicalUtils folder
|
||||
|
||||
all: PA09_Main
|
||||
|
||||
PA09_Main: $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -o PA09_Main
|
||||
|
||||
PA09_Main.o: PA09_Main.c
|
||||
$(CC) -c PA09_Main.c -o PA09_Main.o
|
||||
|
||||
GeneralUtility.o: GeneralUtility.c
|
||||
$(CC) -c GeneralUtility.c -o GeneralUtility.o
|
||||
|
||||
HeapUtility.o: HeapUtility.c
|
||||
$(CC) -c HeapUtility.c -o HeapUtility.o
|
||||
|
||||
StudentUtility.o: StudentUtility.c
|
||||
$(CC) -c StudentUtility.c -o StudentUtility.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) PA09_Main PA09_Main.out
|
||||
|
||||
clean_objects:
|
||||
rm -f $(OBJECTS)
|
||||
|
||||
run:
|
||||
./PA09_Main
|
||||
|
||||
run_win:
|
||||
PA09_Main
|
||||
240
PA10-1115/PA10_Main.c
Normal file
240
PA10-1115/PA10_Main.c
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
// header files
|
||||
#include "File_Input_Utility.h"
|
||||
#include "HashUtility.h"
|
||||
|
||||
// constants
|
||||
extern const int ITEM_NOT_FOUND;
|
||||
extern const bool USED_NODE;
|
||||
extern const bool UNUSED_NODE;
|
||||
|
||||
// prototypes
|
||||
void getQueryObject( StateDataType *returnedState, const char *stateName );
|
||||
ProbingHashType *uploadData( char *fileName, int tableSize, int probeType );
|
||||
|
||||
// main function
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
ProbingHashType *hashTest;
|
||||
StateDataType toRemove, removed, toFind, found;
|
||||
char toRemoveStr[ MAX_STR_LEN ], removedStr[ MAX_STR_LEN ];
|
||||
char toFindStr[ MAX_STR_LEN ], foundStr[ MAX_STR_LEN ];
|
||||
int primeTableSize = 67; // recommended to be prime number (or at least odd)
|
||||
// and roughly 1.3x the size of the data set
|
||||
|
||||
// title
|
||||
printf( "\nHASH TABLE TEST PROGRAM\n" );
|
||||
printf( "=======================\n" );
|
||||
|
||||
hashTest = uploadData( "inData.csv", primeTableSize, QUADRATIC_PROBING );
|
||||
|
||||
// display array dump
|
||||
displayHashTable( hashTest );
|
||||
|
||||
// show hash table status
|
||||
showHashTableStatus( *hashTest );
|
||||
|
||||
printf( "\n\nFinding Selected States ----------------------------------\n" );
|
||||
|
||||
privateCopyString( toFindStr, "Arizona" );
|
||||
getQueryObject( &toFind, toFindStr );
|
||||
found = findItem( hashTest, toFind );
|
||||
stateDataToString( foundStr, found );
|
||||
printf( "Found: %s\n", foundStr );
|
||||
|
||||
privateCopyString( toFindStr, "Iowa" );
|
||||
getQueryObject( &toFind, toFindStr );
|
||||
found = findItem( hashTest, toFind );
|
||||
stateDataToString( foundStr, found );
|
||||
printf( "Found: %s\n", foundStr );
|
||||
|
||||
privateCopyString( toFindStr, "Minnesota" );
|
||||
getQueryObject( &toFind, toFindStr );
|
||||
found = findItem( hashTest, toFind );
|
||||
stateDataToString( foundStr, found );
|
||||
printf( "Found: %s\n", foundStr );
|
||||
|
||||
printf( "\n\nRemoving Selected States ----------------------------------\n" );
|
||||
|
||||
privateCopyString( toRemoveStr, "Texas" );
|
||||
getQueryObject( &toRemove, toRemoveStr );
|
||||
if( removeState( &removed, toRemove, *hashTest ) )
|
||||
{
|
||||
stateDataToString( removedStr, removed );
|
||||
printf( "---Removed: %s\n", removedStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "---Failed to remove %s\n", toRemoveStr );
|
||||
}
|
||||
|
||||
privateCopyString( toRemoveStr, "New Mexico" );
|
||||
getQueryObject( &toRemove, toRemoveStr );
|
||||
if( removeState( &removed, toRemove, *hashTest ) )
|
||||
{
|
||||
stateDataToString( removedStr, removed );
|
||||
printf( "---Removed: %s\n", removedStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "---Failed to remove %s\n", toRemoveStr );
|
||||
}
|
||||
|
||||
privateCopyString( toRemoveStr, "Washington" );
|
||||
getQueryObject( &toRemove, toRemoveStr );
|
||||
if( removeState( &removed, toRemove, *hashTest ) )
|
||||
{
|
||||
stateDataToString( removedStr, removed );
|
||||
printf( "---Removed: %s\n", removedStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "---Failed to remove %s\n", toRemoveStr );
|
||||
}
|
||||
|
||||
privateCopyString( toRemoveStr, "Maryland" );
|
||||
getQueryObject( &toRemove, toRemoveStr );
|
||||
if( removeState( &removed, toRemove, *hashTest ) )
|
||||
{
|
||||
stateDataToString( removedStr, removed );
|
||||
printf( "---Removed: %s\n", removedStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "---Failed to remove %s\n", toRemoveStr );
|
||||
}
|
||||
|
||||
privateCopyString( toRemoveStr, "Florida" );
|
||||
getQueryObject( &toRemove, toRemoveStr );
|
||||
if( removeState( &removed, toRemove, *hashTest ) )
|
||||
{
|
||||
stateDataToString( removedStr, removed );
|
||||
printf( "---Removed: %s\n", removedStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "---Failed to remove %s\n", toRemoveStr );
|
||||
}
|
||||
|
||||
privateCopyString( toRemoveStr, "Quebec" );
|
||||
getQueryObject( &toRemove, toRemoveStr );
|
||||
if( removeState( &removed, toRemove, *hashTest ) )
|
||||
{
|
||||
stateDataToString( removedStr, removed );
|
||||
printf( "---Removed: %s\n", removedStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "---Failed to remove %s\n", toRemoveStr );
|
||||
}
|
||||
|
||||
// display array dump
|
||||
displayHashTable( hashTest );
|
||||
|
||||
// show hash table status
|
||||
showHashTableStatus( *hashTest );
|
||||
|
||||
// end program
|
||||
|
||||
// clear hash table
|
||||
clearHashTable( hashTest );
|
||||
|
||||
// show program end
|
||||
printf( "\nEnd Program\n" );
|
||||
|
||||
// return success
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void getQueryObject( StateDataType *returnedState, const char *stateName )
|
||||
{
|
||||
setDataNodeFromData( returnedState, stateName, 0.0, 0.0, 0.0, 0.0 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Name: getDataFromFile
|
||||
Process: uploads data from file with unknown number of data sets,
|
||||
has internal Verbose Boolean to display input operation
|
||||
Function input/parameters: file name (char *)
|
||||
Function output/parameters: none
|
||||
Function output/returned: pointer to hash table (ProbingHashType *)
|
||||
Device input/file: data from HD
|
||||
Device output/monitor: none
|
||||
Dependencies: initializeHashTable, openInputFile, readStringToDelimiterFromFile,
|
||||
readDoubleFromFile, readCharacterFromFile, printf,
|
||||
addItemFromData, closeInputFile, free
|
||||
*/
|
||||
ProbingHashType *uploadData( char *fileName, int tableSize, int probeType )
|
||||
{
|
||||
char stateNameStr[ MAX_STR_LEN ];
|
||||
double avgTemp, lowestTemp, highestTemp;
|
||||
int index = 0;
|
||||
bool verbose = true; // Set to true to verify data upload, false otherwise
|
||||
ProbingHashType *tempHashPtr = initializeHashTable( tableSize, probeType );
|
||||
|
||||
if( openInputFile( fileName ) )
|
||||
{
|
||||
if( verbose )
|
||||
{
|
||||
printf( "\n ----- Verbose: Begin Loading Data From File\n" );
|
||||
}
|
||||
|
||||
// get first state name
|
||||
readStringToDelimiterFromFile( COMMA, stateNameStr );
|
||||
|
||||
while( !checkForEndOfInputFile() )
|
||||
{
|
||||
avgTemp = readDoubleFromFile();
|
||||
|
||||
// ignores comma
|
||||
readCharacterFromFile();
|
||||
|
||||
lowestTemp = readDoubleFromFile();
|
||||
|
||||
// ignores comma
|
||||
readCharacterFromFile();
|
||||
|
||||
highestTemp = readDoubleFromFile();
|
||||
|
||||
if( verbose )
|
||||
{
|
||||
printf( "State Name: %s | ", stateNameStr );
|
||||
|
||||
printf( "Average Temp: %5.2f | ", avgTemp );
|
||||
|
||||
printf( "Lowest Temp: %5.2f | ", lowestTemp );
|
||||
|
||||
printf( "Highest Temp: %5.2f\n", highestTemp );
|
||||
}
|
||||
|
||||
// add to hash table
|
||||
addItemFromData( tempHashPtr, stateNameStr,
|
||||
avgTemp, lowestTemp, highestTemp );
|
||||
|
||||
// reprime - read next state name
|
||||
readStringToDelimiterFromFile( COMMA, stateNameStr );
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
if( verbose )
|
||||
{
|
||||
printf( "\n ----- Verbose: Items found in file: %d\n", index );
|
||||
printf( " ----- Verbose: End Loading Data From File\n\n" );
|
||||
}
|
||||
|
||||
closeInputFile();
|
||||
}
|
||||
|
||||
// file not found
|
||||
else
|
||||
{
|
||||
free( tempHashPtr );
|
||||
}
|
||||
|
||||
return tempHashPtr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
399
PA10-1115/PA10_SampleRun.txt
Normal file
399
PA10-1115/PA10_SampleRun.txt
Normal file
|
|
@ -0,0 +1,399 @@
|
|||
HASH TABLE TEST PROGRAM
|
||||
=======================
|
||||
|
||||
----- Verbose: Begin Loading Data From File
|
||||
State Name: Massachusetts | Average Temp: 41.00 | Lowest Temp: -35.00 | Highest Temp: 107.00
|
||||
|
||||
Indices probed: 44
|
||||
Massachusetts, Avg: 41.00, Low: -35.00, High: 107.00, 44 -> 44
|
||||
State Name: Rhode Island | Average Temp: 50.10 | Lowest Temp: -25.00 | Highest Temp: 104.00
|
||||
|
||||
Indices probed: 61
|
||||
Rhode Island, Avg: 50.10, Low: -25.00, High: 104.00, 61 -> 61
|
||||
State Name: Wyoming | Average Temp: 42.00 | Lowest Temp: -66.00 | Highest Temp: 115.00
|
||||
|
||||
Indices probed: 9
|
||||
Wyoming, Avg: 42.00, Low: -66.00, High: 115.00, 9 -> 9
|
||||
State Name: New Mexico | Average Temp: 52.70 | Lowest Temp: -50.00 | Highest Temp: 122.00
|
||||
|
||||
Indices probed: 5
|
||||
New Mexico, Avg: 52.70, Low: -50.00, High: 122.00, 5 -> 5
|
||||
State Name: Tennessee | Average Temp: 57.60 | Lowest Temp: -32.00 | Highest Temp: 113.00
|
||||
|
||||
Indices probed: 0
|
||||
Tennessee, Avg: 57.60, Low: -32.00, High: 113.00, 0 -> 0
|
||||
State Name: South Dakota | Average Temp: 45.20 | Lowest Temp: -58.00 | Highest Temp: 120.00
|
||||
|
||||
Indices probed: 20
|
||||
South Dakota, Avg: 45.20, Low: -58.00, High: 120.00, 20 -> 20
|
||||
State Name: Indiana | Average Temp: 47.80 | Lowest Temp: -36.00 | Highest Temp: 116.00
|
||||
|
||||
Indices probed: 22
|
||||
Indiana, Avg: 47.80, Low: -36.00, High: 116.00, 22 -> 22
|
||||
State Name: Arkansas | Average Temp: 60.30 | Lowest Temp: -29.00 | Highest Temp: 120.00
|
||||
|
||||
Indices probed: 16
|
||||
Arkansas, Avg: 60.30, Low: -29.00, High: 120.00, 16 -> 16
|
||||
State Name: Kansas | Average Temp: 54.30 | Lowest Temp: -40.00 | Highest Temp: 121.00
|
||||
|
||||
Indices probed: 14
|
||||
Kansas, Avg: 54.30, Low: -40.00, High: 121.00, 14 -> 14
|
||||
State Name: Minnesota | Average Temp: 41.20 | Lowest Temp: -60.00 | Highest Temp: 114.00
|
||||
|
||||
Indices probed: 4
|
||||
Minnesota, Avg: 41.20, Low: -60.00, High: 114.00, 4 -> 4
|
||||
State Name: North Dakota | Average Temp: 40.40 | Lowest Temp: -60.00 | Highest Temp: 121.00
|
||||
|
||||
Indices probed: 12
|
||||
North Dakota, Avg: 40.40, Low: -60.00, High: 121.00, 12 -> 12
|
||||
State Name: Vermont | Average Temp: 42.90 | Lowest Temp: -50.00 | Highest Temp: 105.00
|
||||
|
||||
Indices probed: 10
|
||||
Vermont, Avg: 42.90, Low: -50.00, High: 105.00, 10 -> 10
|
||||
State Name: Oregon | Average Temp: 48.40 | Lowest Temp: -54.00 | Highest Temp: 119.00
|
||||
|
||||
Indices probed: 27
|
||||
Oregon, Avg: 48.40, Low: -54.00, High: 119.00, 27 -> 27
|
||||
State Name: West Virginia | Average Temp: 51.80 | Lowest Temp: -37.00 | Highest Temp: 112.00
|
||||
|
||||
Indices probed: 3
|
||||
West Virginia, Avg: 51.80, Low: -37.00, High: 112.00, 3 -> 3
|
||||
State Name: Montana | Average Temp: 42.70 | Lowest Temp: -70.00 | Highest Temp: 117.00
|
||||
|
||||
Indices probed: 48
|
||||
Montana, Avg: 42.70, Low: -70.00, High: 117.00, 48 -> 48
|
||||
State Name: Idaho | Average Temp: 51.80 | Lowest Temp: -60.00 | Highest Temp: 118.00
|
||||
|
||||
Indices probed: 55
|
||||
Idaho, Avg: 51.80, Low: -60.00, High: 118.00, 55 -> 55
|
||||
State Name: Nevada | Average Temp: 53.40 | Lowest Temp: -50.00 | Highest Temp: 125.00
|
||||
|
||||
Indices probed: 66
|
||||
Nevada, Avg: 53.40, Low: -50.00, High: 125.00, 66 -> 66
|
||||
State Name: Missouri | Average Temp: 63.40 | Lowest Temp: -40.00 | Highest Temp: 118.00
|
||||
|
||||
Indices probed: 55, 56
|
||||
Missouri, Avg: 63.40, Low: -40.00, High: 118.00, 55 -> 56
|
||||
State Name: Utah | Average Temp: 48.60 | Lowest Temp: -69.00 | Highest Temp: 117.00
|
||||
|
||||
Indices probed: 30
|
||||
Utah, Avg: 48.60, Low: -69.00, High: 117.00, 30 -> 30
|
||||
State Name: Hawaii | Average Temp: 70.00 | Lowest Temp: 12.00 | Highest Temp: 100.00
|
||||
|
||||
Indices probed: 64
|
||||
Hawaii, Avg: 70.00, Low: 12.00, High: 100.00, 64 -> 64
|
||||
State Name: South Carolina | Average Temp: 62.40 | Lowest Temp: -19.00 | Highest Temp: 111.00
|
||||
|
||||
Indices probed: 32
|
||||
South Carolina, Avg: 62.40, Low: -19.00, High: 111.00, 32 -> 32
|
||||
State Name: North Carolina | Average Temp: 59.00 | Lowest Temp: -34.00 | Highest Temp: 110.00
|
||||
|
||||
Indices probed: 24
|
||||
North Carolina, Avg: 59.00, Low: -34.00, High: 110.00, 24 -> 24
|
||||
State Name: Maine | Average Temp: 47.90 | Lowest Temp: -50.00 | Highest Temp: 105.00
|
||||
|
||||
Indices probed: 61, 62
|
||||
Maine, Avg: 47.90, Low: -50.00, High: 105.00, 61 -> 62
|
||||
State Name: Texas | Average Temp: 64.80 | Lowest Temp: -23.00 | Highest Temp: 120.00
|
||||
|
||||
Indices probed: 32, 33
|
||||
Texas, Avg: 64.80, Low: -23.00, High: 120.00, 32 -> 33
|
||||
State Name: Kentucky | Average Temp: 55.60 | Lowest Temp: -37.00 | Highest Temp: 114.00
|
||||
|
||||
Indices probed: 42
|
||||
Kentucky, Avg: 55.60, Low: -37.00, High: 114.00, 42 -> 42
|
||||
State Name: Colorado | Average Temp: 45.10 | Lowest Temp: -61.00 | Highest Temp: 118.00
|
||||
|
||||
Indices probed: 15
|
||||
Colorado, Avg: 45.10, Low: -61.00, High: 118.00, 15 -> 15
|
||||
State Name: Michigan | Average Temp: 44.40 | Lowest Temp: -51.00 | Highest Temp: 112.00
|
||||
|
||||
Indices probed: 63
|
||||
Michigan, Avg: 44.40, Low: -51.00, High: 112.00, 63 -> 63
|
||||
State Name: Ohio | Average Temp: 50.70 | Lowest Temp: -39.00 | Highest Temp: 113.00
|
||||
|
||||
Indices probed: 17
|
||||
Ohio, Avg: 50.70, Low: -39.00, High: 113.00, 17 -> 17
|
||||
State Name: Pennsylvania | Average Temp: 48.80 | Lowest Temp: -42.00 | Highest Temp: 111.00
|
||||
|
||||
Indices probed: 66, 0, 3, 8
|
||||
Pennsylvania, Avg: 48.80, Low: -42.00, High: 111.00, 66 -> 8
|
||||
State Name: Florida | Average Temp: 70.70 | Lowest Temp: -2.00 | Highest Temp: 109.00
|
||||
|
||||
Indices probed: 35
|
||||
Florida, Avg: 70.70, Low: -2.00, High: 109.00, 35 -> 35
|
||||
State Name: Louisiana | Average Temp: 66.40 | Lowest Temp: -16.00 | Highest Temp: 114.00
|
||||
|
||||
Indices probed: 62, 63, 66, 4, 11
|
||||
Louisiana, Avg: 66.40, Low: -16.00, High: 114.00, 62 -> 11
|
||||
State Name: Oklahoma | Average Temp: 59.60 | Lowest Temp: -27.00 | Highest Temp: 120.00
|
||||
|
||||
Indices probed: 8, 9, 12, 17, 24, 33, 44, 57
|
||||
Oklahoma, Avg: 59.60, Low: -27.00, High: 120.00, 8 -> 57
|
||||
State Name: Mississippi | Average Temp: 54.50 | Lowest Temp: -19.00 | Highest Temp: 115.00
|
||||
|
||||
Indices probed: 42, 43
|
||||
Mississippi, Avg: 54.50, Low: -19.00, High: 115.00, 42 -> 43
|
||||
State Name: New Jersey | Average Temp: 43.80 | Lowest Temp: -34.00 | Highest Temp: 110.00
|
||||
|
||||
Indices probed: 18
|
||||
New Jersey, Avg: 43.80, Low: -34.00, High: 110.00, 18 -> 18
|
||||
State Name: Iowa | Average Temp: 44.40 | Lowest Temp: -47.00 | Highest Temp: 118.00
|
||||
|
||||
Indices probed: 33, 34
|
||||
Iowa, Avg: 44.40, Low: -47.00, High: 118.00, 33 -> 34
|
||||
State Name: New York | Average Temp: 45.40 | Lowest Temp: -52.00 | Highest Temp: 108.00
|
||||
|
||||
Indices probed: 14, 15, 18, 23
|
||||
New York, Avg: 45.40, Low: -52.00, High: 108.00, 14 -> 23
|
||||
State Name: Virginia | Average Temp: 55.10 | Lowest Temp: -30.00 | Highest Temp: 110.00
|
||||
|
||||
Indices probed: 21
|
||||
Virginia, Avg: 55.10, Low: -30.00, High: 110.00, 21 -> 21
|
||||
State Name: Alabama | Average Temp: 26.60 | Lowest Temp: -27.00 | Highest Temp: 112.00
|
||||
|
||||
Indices probed: 1
|
||||
Alabama, Avg: 26.60, Low: -27.00, High: 112.00, 1 -> 1
|
||||
State Name: Delaware | Average Temp: 55.30 | Lowest Temp: -17.00 | Highest Temp: 110.00
|
||||
|
||||
Indices probed: 1, 2
|
||||
Delaware, Avg: 55.30, Low: -17.00, High: 110.00, 1 -> 2
|
||||
State Name: Wisconsin | Average Temp: 43.10 | Lowest Temp: -55.00 | Highest Temp: 114.00
|
||||
|
||||
Indices probed: 19
|
||||
Wisconsin, Avg: 43.10, Low: -55.00, High: 114.00, 19 -> 19
|
||||
State Name: New Hampshire | Average Temp: 49.90 | Lowest Temp: -47.00 | Highest Temp: 106.00
|
||||
|
||||
Indices probed: 53
|
||||
New Hampshire, Avg: 49.90, Low: -47.00, High: 106.00, 53 -> 53
|
||||
State Name: Illinois | Average Temp: 51.70 | Lowest Temp: -36.00 | Highest Temp: 117.00
|
||||
|
||||
Indices probed: 31
|
||||
Illinois, Avg: 51.70, Low: -36.00, High: 117.00, 31 -> 31
|
||||
State Name: Arizona | Average Temp: 60.40 | Lowest Temp: -40.00 | Highest Temp: 128.00
|
||||
|
||||
Indices probed: 54
|
||||
Arizona, Avg: 60.40, Low: -40.00, High: 128.00, 54 -> 54
|
||||
State Name: Maryland | Average Temp: 54.20 | Lowest Temp: -40.00 | Highest Temp: 109.00
|
||||
|
||||
Indices probed: 20, 21, 24, 29
|
||||
Maryland, Avg: 54.20, Low: -40.00, High: 109.00, 20 -> 29
|
||||
State Name: Nebraska | Average Temp: 48.80 | Lowest Temp: -47.00 | Highest Temp: 118.00
|
||||
|
||||
Indices probed: 3, 4, 7
|
||||
Nebraska, Avg: 48.80, Low: -47.00, High: 118.00, 3 -> 7
|
||||
State Name: California | Average Temp: 59.40 | Lowest Temp: -45.00 | Highest Temp: 134.00
|
||||
|
||||
Indices probed: 11, 12, 15, 20, 27, 36
|
||||
California, Avg: 59.40, Low: -45.00, High: 134.00, 11 -> 36
|
||||
State Name: Washington | Average Temp: 48.30 | Lowest Temp: -48.00 | Highest Temp: 118.00
|
||||
|
||||
Indices probed: 53, 54, 57, 62, 2, 11, 22, 35, 50
|
||||
Washington, Avg: 48.30, Low: -48.00, High: 118.00, 53 -> 50
|
||||
State Name: Georgia | Average Temp: 63.50 | Lowest Temp: -17.00 | Highest Temp: 112.00
|
||||
|
||||
Indices probed: 32, 33, 36, 41
|
||||
Georgia, Avg: 63.50, Low: -17.00, High: 112.00, 32 -> 41
|
||||
State Name: Connecticut | Average Temp: 49.00 | Lowest Temp: -32.00 | Highest Temp: 106.00
|
||||
|
||||
Indices probed: 12, 13
|
||||
Connecticut, Avg: 49.00, Low: -32.00, High: 106.00, 12 -> 13
|
||||
State Name: Alaska | Average Temp: 62.80 | Lowest Temp: -80.00 | Highest Temp: 100.00
|
||||
|
||||
Indices probed: 51
|
||||
Alaska, Avg: 62.80, Low: -80.00, High: 100.00, 51 -> 51
|
||||
|
||||
----- Verbose: Items found in file: 50
|
||||
----- Verbose: End Loading Data From File
|
||||
|
||||
|
||||
HASH TABLE ARRAY DUMP:
|
||||
1) Tennessee, Avg: 57.60, Low: -32.00, High: 113.00
|
||||
2) Alabama, Avg: 26.60, Low: -27.00, High: 112.00
|
||||
3) Delaware, Avg: 55.30, Low: -17.00, High: 110.00
|
||||
4) West Virginia, Avg: 51.80, Low: -37.00, High: 112.00
|
||||
5) Minnesota, Avg: 41.20, Low: -60.00, High: 114.00
|
||||
6) New Mexico, Avg: 52.70, Low: -50.00, High: 122.00
|
||||
7) Unused
|
||||
8) Nebraska, Avg: 48.80, Low: -47.00, High: 118.00
|
||||
9) Pennsylvania, Avg: 48.80, Low: -42.00, High: 111.00
|
||||
10) Wyoming, Avg: 42.00, Low: -66.00, High: 115.00
|
||||
11) Vermont, Avg: 42.90, Low: -50.00, High: 105.00
|
||||
12) Louisiana, Avg: 66.40, Low: -16.00, High: 114.00
|
||||
13) North Dakota, Avg: 40.40, Low: -60.00, High: 121.00
|
||||
14) Connecticut, Avg: 49.00, Low: -32.00, High: 106.00
|
||||
15) Kansas, Avg: 54.30, Low: -40.00, High: 121.00
|
||||
16) Colorado, Avg: 45.10, Low: -61.00, High: 118.00
|
||||
17) Arkansas, Avg: 60.30, Low: -29.00, High: 120.00
|
||||
18) Ohio, Avg: 50.70, Low: -39.00, High: 113.00
|
||||
19) New Jersey, Avg: 43.80, Low: -34.00, High: 110.00
|
||||
20) Wisconsin, Avg: 43.10, Low: -55.00, High: 114.00
|
||||
21) South Dakota, Avg: 45.20, Low: -58.00, High: 120.00
|
||||
22) Virginia, Avg: 55.10, Low: -30.00, High: 110.00
|
||||
23) Indiana, Avg: 47.80, Low: -36.00, High: 116.00
|
||||
24) New York, Avg: 45.40, Low: -52.00, High: 108.00
|
||||
25) North Carolina, Avg: 59.00, Low: -34.00, High: 110.00
|
||||
26) Unused
|
||||
27) Unused
|
||||
28) Oregon, Avg: 48.40, Low: -54.00, High: 119.00
|
||||
29) Unused
|
||||
30) Maryland, Avg: 54.20, Low: -40.00, High: 109.00
|
||||
31) Utah, Avg: 48.60, Low: -69.00, High: 117.00
|
||||
32) Illinois, Avg: 51.70, Low: -36.00, High: 117.00
|
||||
33) South Carolina, Avg: 62.40, Low: -19.00, High: 111.00
|
||||
34) Texas, Avg: 64.80, Low: -23.00, High: 120.00
|
||||
35) Iowa, Avg: 44.40, Low: -47.00, High: 118.00
|
||||
36) Florida, Avg: 70.70, Low: -2.00, High: 109.00
|
||||
37) California, Avg: 59.40, Low: -45.00, High: 134.00
|
||||
38) Unused
|
||||
39) Unused
|
||||
40) Unused
|
||||
41) Unused
|
||||
42) Georgia, Avg: 63.50, Low: -17.00, High: 112.00
|
||||
43) Kentucky, Avg: 55.60, Low: -37.00, High: 114.00
|
||||
44) Mississippi, Avg: 54.50, Low: -19.00, High: 115.00
|
||||
45) Massachusetts, Avg: 41.00, Low: -35.00, High: 107.00
|
||||
46) Unused
|
||||
47) Unused
|
||||
48) Unused
|
||||
49) Montana, Avg: 42.70, Low: -70.00, High: 117.00
|
||||
50) Unused
|
||||
51) Washington, Avg: 48.30, Low: -48.00, High: 118.00
|
||||
52) Alaska, Avg: 62.80, Low: -80.00, High: 100.00
|
||||
53) Unused
|
||||
54) New Hampshire, Avg: 49.90, Low: -47.00, High: 106.00
|
||||
55) Arizona, Avg: 60.40, Low: -40.00, High: 128.00
|
||||
56) Idaho, Avg: 51.80, Low: -60.00, High: 118.00
|
||||
57) Missouri, Avg: 63.40, Low: -40.00, High: 118.00
|
||||
58) Oklahoma, Avg: 59.60, Low: -27.00, High: 120.00
|
||||
59) Unused
|
||||
60) Unused
|
||||
61) Unused
|
||||
62) Rhode Island, Avg: 50.10, Low: -25.00, High: 104.00
|
||||
63) Maine, Avg: 47.90, Low: -50.00, High: 105.00
|
||||
64) Michigan, Avg: 44.40, Low: -51.00, High: 112.00
|
||||
65) Hawaii, Avg: 70.00, Low: 12.00, High: 100.00
|
||||
66) Unused
|
||||
67) Nevada, Avg: 53.40, Low: -50.00, High: 125.00
|
||||
|
||||
|
||||
Hash Table Status: DDDDDDUDDDDDDDDDDDDDDDDDDUUDUDDDDDDDDUUUUDDDDUUUDUDDUDDDDDUUUDDDDUD
|
||||
D => Data, U => Unused
|
||||
|
||||
Items in Hash Table: 50
|
||||
Minimum contiguous bins: 1
|
||||
Maximum contiguous bins: 18
|
||||
Number of empty bins: 17
|
||||
|
||||
|
||||
Finding Selected States ----------------------------------
|
||||
|
||||
Indices probed: 54
|
||||
Found: Arizona, Avg: 60.40, Low: -40.00, High: 128.00
|
||||
|
||||
Indices probed: 33, 34
|
||||
Found: Iowa, Avg: 44.40, Low: -47.00, High: 118.00
|
||||
|
||||
Indices probed: 4
|
||||
Found: Minnesota, Avg: 41.20, Low: -60.00, High: 114.00
|
||||
|
||||
|
||||
Removing Selected States ----------------------------------
|
||||
|
||||
Indices probed: 32, 33
|
||||
---Removed: Texas, Avg: 64.80, Low: -23.00, High: 120.00
|
||||
|
||||
Indices probed: 5
|
||||
---Removed: New Mexico, Avg: 52.70, Low: -50.00, High: 122.00
|
||||
|
||||
Indices probed: 53, 54, 57, 62, 2, 11, 22, 35, 50
|
||||
---Removed: Washington, Avg: 48.30, Low: -48.00, High: 118.00
|
||||
|
||||
Indices probed: 20, 21, 24, 29
|
||||
---Removed: Maryland, Avg: 54.20, Low: -40.00, High: 109.00
|
||||
|
||||
Indices probed: 35
|
||||
---Removed: Florida, Avg: 70.70, Low: -2.00, High: 109.00
|
||||
|
||||
Indices probed: 8, 9, 12, 17, 24, 33, 44, 57, 5, 22, 41, 62, 18, 43, 3, 32, 63, 29, 64, 34, 6, 47, 23, 1, 48, 30, 14, 0, 55, 45, 37, 31, 27, 25, 25, 27, 31, 37, 45, 55, 0, 14, 30, 48, 1, 23, 47, 6, 34, 64, 29, 63, 32, 3, 43, 18, 62, 41, 22, 5, 57, 44, 33, 24, 17, 12, 9, 8
|
||||
---Failed to remove Quebec
|
||||
|
||||
HASH TABLE ARRAY DUMP:
|
||||
1) Tennessee, Avg: 57.60, Low: -32.00, High: 113.00
|
||||
2) Alabama, Avg: 26.60, Low: -27.00, High: 112.00
|
||||
3) Delaware, Avg: 55.30, Low: -17.00, High: 110.00
|
||||
4) West Virginia, Avg: 51.80, Low: -37.00, High: 112.00
|
||||
5) Minnesota, Avg: 41.20, Low: -60.00, High: 114.00
|
||||
6) Unused
|
||||
7) Unused
|
||||
8) Nebraska, Avg: 48.80, Low: -47.00, High: 118.00
|
||||
9) Pennsylvania, Avg: 48.80, Low: -42.00, High: 111.00
|
||||
10) Wyoming, Avg: 42.00, Low: -66.00, High: 115.00
|
||||
11) Vermont, Avg: 42.90, Low: -50.00, High: 105.00
|
||||
12) Louisiana, Avg: 66.40, Low: -16.00, High: 114.00
|
||||
13) North Dakota, Avg: 40.40, Low: -60.00, High: 121.00
|
||||
14) Connecticut, Avg: 49.00, Low: -32.00, High: 106.00
|
||||
15) Kansas, Avg: 54.30, Low: -40.00, High: 121.00
|
||||
16) Colorado, Avg: 45.10, Low: -61.00, High: 118.00
|
||||
17) Arkansas, Avg: 60.30, Low: -29.00, High: 120.00
|
||||
18) Ohio, Avg: 50.70, Low: -39.00, High: 113.00
|
||||
19) New Jersey, Avg: 43.80, Low: -34.00, High: 110.00
|
||||
20) Wisconsin, Avg: 43.10, Low: -55.00, High: 114.00
|
||||
21) South Dakota, Avg: 45.20, Low: -58.00, High: 120.00
|
||||
22) Virginia, Avg: 55.10, Low: -30.00, High: 110.00
|
||||
23) Indiana, Avg: 47.80, Low: -36.00, High: 116.00
|
||||
24) New York, Avg: 45.40, Low: -52.00, High: 108.00
|
||||
25) North Carolina, Avg: 59.00, Low: -34.00, High: 110.00
|
||||
26) Unused
|
||||
27) Unused
|
||||
28) Oregon, Avg: 48.40, Low: -54.00, High: 119.00
|
||||
29) Unused
|
||||
30) Unused
|
||||
31) Utah, Avg: 48.60, Low: -69.00, High: 117.00
|
||||
32) Illinois, Avg: 51.70, Low: -36.00, High: 117.00
|
||||
33) South Carolina, Avg: 62.40, Low: -19.00, High: 111.00
|
||||
34) Unused
|
||||
35) Iowa, Avg: 44.40, Low: -47.00, High: 118.00
|
||||
36) Unused
|
||||
37) California, Avg: 59.40, Low: -45.00, High: 134.00
|
||||
38) Unused
|
||||
39) Unused
|
||||
40) Unused
|
||||
41) Unused
|
||||
42) Georgia, Avg: 63.50, Low: -17.00, High: 112.00
|
||||
43) Kentucky, Avg: 55.60, Low: -37.00, High: 114.00
|
||||
44) Mississippi, Avg: 54.50, Low: -19.00, High: 115.00
|
||||
45) Massachusetts, Avg: 41.00, Low: -35.00, High: 107.00
|
||||
46) Unused
|
||||
47) Unused
|
||||
48) Unused
|
||||
49) Montana, Avg: 42.70, Low: -70.00, High: 117.00
|
||||
50) Unused
|
||||
51) Unused
|
||||
52) Alaska, Avg: 62.80, Low: -80.00, High: 100.00
|
||||
53) Unused
|
||||
54) New Hampshire, Avg: 49.90, Low: -47.00, High: 106.00
|
||||
55) Arizona, Avg: 60.40, Low: -40.00, High: 128.00
|
||||
56) Idaho, Avg: 51.80, Low: -60.00, High: 118.00
|
||||
57) Missouri, Avg: 63.40, Low: -40.00, High: 118.00
|
||||
58) Oklahoma, Avg: 59.60, Low: -27.00, High: 120.00
|
||||
59) Unused
|
||||
60) Unused
|
||||
61) Unused
|
||||
62) Rhode Island, Avg: 50.10, Low: -25.00, High: 104.00
|
||||
63) Maine, Avg: 47.90, Low: -50.00, High: 105.00
|
||||
64) Michigan, Avg: 44.40, Low: -51.00, High: 112.00
|
||||
65) Hawaii, Avg: 70.00, Low: 12.00, High: 100.00
|
||||
66) Unused
|
||||
67) Nevada, Avg: 53.40, Low: -50.00, High: 125.00
|
||||
|
||||
|
||||
Hash Table Status: DDDDDUUDDDDDDDDDDDDDDDDDDUUDUUDDDUDUDUUUUDDDDUUUDUUDUDDDDDUUUDDDDUD
|
||||
D => Data, U => Unused
|
||||
|
||||
Items in Hash Table: 45
|
||||
Minimum contiguous bins: 1
|
||||
Maximum contiguous bins: 18
|
||||
Number of empty bins: 22
|
||||
|
||||
End Program
|
||||
73
PA10-1115/StandardConstants.h
Normal file
73
PA10-1115/StandardConstants.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// Preprocessor directives
|
||||
#ifndef STANDARD_CONSTANTS_H
|
||||
#define STANDARD_CONSTANTS_H
|
||||
|
||||
// Include Boolean
|
||||
#include <stdbool.h>
|
||||
|
||||
// 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
|
||||
83
PA10-1115/StateDataUtility.c
Normal file
83
PA10-1115/StateDataUtility.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// header files
|
||||
#include "StateDataUtility.h"
|
||||
|
||||
/* Data Structures
|
||||
typedef struct StateStruct
|
||||
{
|
||||
char name[ STD_STR_LEN ];
|
||||
|
||||
double averageTemp, lowestTemp, highestTemp;
|
||||
|
||||
bool inUse;
|
||||
} StateDataType;
|
||||
Data Structures */
|
||||
|
||||
// function definitions
|
||||
|
||||
/*
|
||||
Name: setDataNodeFromData
|
||||
Process: sets given values into a given StateDataType struct,
|
||||
using individual struct data
|
||||
Function input/parameters: provided name (const char *),
|
||||
average, lowest, and highest temperatures (double),
|
||||
and node in use state
|
||||
Function output/parameters: updated state data pointer (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: privateCopyString
|
||||
*/
|
||||
void setDataNodeFromData( StateDataType *nodePtr, const char *name,
|
||||
double avgTemp, double lowTemp, double highTemp, bool nodeState )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: setDataNodeFromStruct
|
||||
Process: sets given values into a given StateDataType struct,
|
||||
using another data struct
|
||||
Function input/parameters: provided state data source struct
|
||||
(const StateDataType)
|
||||
Function output/parameters: updated state data pointer (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: setDataNodeFromData
|
||||
*/
|
||||
void setDataNodeFromStruct( StateDataType *nodePtr,
|
||||
const StateDataType source )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: stateDataToString
|
||||
Process: creates string from StateDataType data
|
||||
Function input/parameters: provided state data (const StateDataType)
|
||||
Function output/parameters: output string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: sprintf, or other options
|
||||
*/
|
||||
void stateDataToString( char *outStr, const StateDataType state )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: setEmptyDataNode
|
||||
Process: sets given node values to string "---", zero values,
|
||||
and Boolean in use variable to false
|
||||
Function input/parameters: state data struct (StateDataType *)
|
||||
Function output/parameters: updated state data struct (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: privateCopyString
|
||||
*/
|
||||
void setEmptyDataNode( StateDataType *node )
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
74
PA10-1115/StateDataUtility.h
Normal file
74
PA10-1115/StateDataUtility.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#ifndef DATA_UTILITIES_H
|
||||
#define DATA_UTILITIES_H
|
||||
|
||||
// header files
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// data structures
|
||||
typedef struct StateStruct
|
||||
{
|
||||
char name[ STD_STR_LEN ];
|
||||
|
||||
double averageTemp, lowestTemp, highestTemp;
|
||||
|
||||
bool inUse;
|
||||
} StateDataType;
|
||||
|
||||
/*
|
||||
Name: setDataNodeFromData
|
||||
Process: sets given values into a given StateDataType struct,
|
||||
using individual struct data
|
||||
Function input/parameters: provided name (const char *),
|
||||
average, lowest, and highest temperatures (double),
|
||||
and node in use state
|
||||
Function output/parameters: updated state data pointer (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: privateCopyString
|
||||
*/
|
||||
void setDataNodeFromData( StateDataType *nodePtr, const char *name,
|
||||
double avgTemp, double lowTemp, double highTemp, bool nodeState );
|
||||
|
||||
/*
|
||||
Name: setDataNodeFromStruct
|
||||
Process: sets given values into a given StateDataType struct,
|
||||
using another data struct
|
||||
Function input/parameters: provided state data source struct
|
||||
(const StateDataType)
|
||||
Function output/parameters: updated state data pointer (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: setDataNodeFromData
|
||||
*/
|
||||
void setDataNodeFromStruct( StateDataType *nodePtr,
|
||||
const StateDataType source );
|
||||
|
||||
/*
|
||||
Name: stateDataToString
|
||||
Process: creates string from StateDataType data
|
||||
Function input/parameters: provided state data (const StateDataType)
|
||||
Function output/parameters: output string (char *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: sprintf, or other options
|
||||
*/
|
||||
void stateDataToString( char *outStr, const StateDataType state );
|
||||
|
||||
/*
|
||||
Name: setEmptyDataNode
|
||||
Process: sets given node values to string "---", zero values,
|
||||
and Boolean in use variable to false
|
||||
Function input/parameters: state data struct (StateDataType *)
|
||||
Function output/parameters: updated state data struct (StateDataType *)
|
||||
Function output/returned: none
|
||||
Device input/---: none
|
||||
Device output/---: none
|
||||
Dependencies: privateCopyString
|
||||
*/
|
||||
void setEmptyDataNode( StateDataType *node );
|
||||
|
||||
|
||||
#endif // DATA_UTILITIES_H
|
||||
50
PA10-1115/inData.csv
Normal file
50
PA10-1115/inData.csv
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
Massachusetts,41,-35,107
|
||||
Rhode Island,50.1,-25,104
|
||||
Wyoming,42,-66,115
|
||||
New Mexico,52.7,-50,122
|
||||
Tennessee,57.6,-32,113
|
||||
South Dakota,45.2,-58,120
|
||||
Indiana,47.8,-36,116
|
||||
Arkansas,60.3,-29,120
|
||||
Kansas,54.3,-40,121
|
||||
Minnesota,41.2,-60,114
|
||||
North Dakota,40.4,-60,121
|
||||
Vermont,42.9,-50,105
|
||||
Oregon,48.4,-54,119
|
||||
West Virginia,51.8,-37,112
|
||||
Montana,42.7,-70,117
|
||||
Idaho,51.8,-60,118
|
||||
Nevada,53.4,-50,125
|
||||
Missouri,63.4,-40,118
|
||||
Utah,48.6,-69,117
|
||||
Hawaii,70,12,100
|
||||
South Carolina,62.4,-19,111
|
||||
North Carolina,59,-34,110
|
||||
Maine,47.9,-50,105
|
||||
Texas,64.8,-23,120
|
||||
Kentucky,55.6,-37,114
|
||||
Colorado,45.1,-61,118
|
||||
Michigan,44.4,-51,112
|
||||
Ohio,50.7,-39,113
|
||||
Pennsylvania,48.8,-42,111
|
||||
Florida,70.7,-2,109
|
||||
Louisiana,66.4,-16,114
|
||||
Oklahoma,59.6,-27,120
|
||||
Mississippi,54.5,-19,115
|
||||
New Jersey,43.8,-34,110
|
||||
Iowa,44.4,-47,118
|
||||
New York,45.4,-52,108
|
||||
Virginia,55.1,-30,110
|
||||
Alabama,26.6,-27,112
|
||||
Delaware,55.3,-17,110
|
||||
Wisconsin,43.1,-55,114
|
||||
New Hampshire,49.9,-47,106
|
||||
Illinois,51.7,-36,117
|
||||
Arizona,60.4,-40,128
|
||||
Maryland,54.2,-40,109
|
||||
Nebraska,48.8,-47,118
|
||||
California,59.4,-45,134
|
||||
Washington,48.3,-48,118
|
||||
Georgia,63.5,-17,112
|
||||
Connecticut,49,-32,106
|
||||
Alaska,62.8,-80,100
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue