Good Stopping Point for 480 Prep
+- Phase6 Preparation to Step 3.
This commit is contained in:
parent
ca321e6c4e
commit
fd87d9a54d
3 changed files with 285 additions and 23 deletions
|
|
@ -16,6 +16,12 @@ Dependencies: included by standard libraries
|
|||
int main()
|
||||
{
|
||||
// define/initialize variables
|
||||
char testStringOne[] = "My New Testing String!!!";
|
||||
char testStringTwo[MAX_STR_LEN];
|
||||
char testStringThree[MAX_STR_LEN];
|
||||
char testStringFour[MAX_STR_LEN];
|
||||
char testStringFive[MAX_STR_LEN];
|
||||
int stringLength, subStrStart;
|
||||
printf("\n---Phase 6: All String Utilities---\n");
|
||||
printf("=====================================\n");
|
||||
// get user input
|
||||
|
|
@ -23,22 +29,50 @@ int main()
|
|||
|
||||
// string length
|
||||
// getStringLength
|
||||
stringLength = getStringLength(testStringOne);
|
||||
printf("\nThe length of string '%s' is %d.\n", testStringOne, stringLength);
|
||||
// string copy
|
||||
// copyString
|
||||
copyString(testStringTwo, testStringOne);
|
||||
printf("\nCopied string '%s' from string '%s'\n", testStringTwo, testStringOne);
|
||||
// string concatenate
|
||||
// catString
|
||||
catString(testStringTwo, " and this is concatenated.");
|
||||
printf("\nConcatenated string: '%s'\n", testStringTwo);
|
||||
// string compare (<, >, =)
|
||||
// compareString
|
||||
if(compareString("ONE", "TWO") > 0)
|
||||
{
|
||||
printf("\n'ONE' is greater than 'TWO'\n");
|
||||
}
|
||||
if(compareString("TWO", "ONE") < 0)
|
||||
{
|
||||
printf("\n'TWO' is less than 'ONE'\n");
|
||||
}
|
||||
if(compareString("ONE", "ONE") == 0)
|
||||
{
|
||||
printf("\n'ONE' is equal to 'ONE'\n");
|
||||
}
|
||||
// string substring get
|
||||
// substringGet
|
||||
getSubString(testStringThree, testStringTwo, 34, 44);
|
||||
printf("\nSubstring found: '%s'\n", testStringThree);
|
||||
// string substring find
|
||||
// substringFind
|
||||
subStrStart = findSubString(testStringTwo, "this is");
|
||||
printf("\nSubstring start: %d\n", subStrStart);
|
||||
// string set to lower
|
||||
// lowerString
|
||||
// strToLowerCase
|
||||
strToLowerCase(testStringFour, testStringTwo);
|
||||
printf("\nLowercase String: '%s'\n", testStringFour);
|
||||
// string get to delimiter
|
||||
// stringDelimiter
|
||||
getStringToDelimiter(stdin, '.', testStringFive);
|
||||
printf("\nCaptured to delimiter: '%s'\n", testStringFive);
|
||||
// string get to end of line
|
||||
// stringEOL
|
||||
getStringToLineEnd(stdin, testStringFive);
|
||||
printf("\nCaptured to end of line: '%s'\n", testStringFive);
|
||||
|
||||
// display results
|
||||
printf("\nProgram End\n");
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
// string substring find
|
||||
// findSubString
|
||||
// string set to lower
|
||||
// lowerString
|
||||
// toLowerCase
|
||||
// string get to delimiter
|
||||
// stringDelimiter
|
||||
// string get to end of line
|
||||
|
|
@ -110,46 +110,128 @@ Process: captures sub string within larger string
|
|||
between two inclusive indices.
|
||||
returns empty string if either index is out of range,
|
||||
assumes enough memory in dest string
|
||||
Function input/parameters: ???
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: ???
|
||||
Function input/parameters: c-style string (char *)
|
||||
start and end indices (int)
|
||||
Function output/parameters: c-style destination string (char *)
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
Dependencies: getStringLength, malloc, copyString, free
|
||||
*/
|
||||
void getSubString(char *destStr, const char *sourceStr,
|
||||
int startIndex, int endIndex)
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: findSubString
|
||||
Process: ???
|
||||
Function input/parameters: ???
|
||||
Process: linear search for given substring within another string
|
||||
Function input/parameters: c-style test string (char *),
|
||||
c-style source string (char *)
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: ???
|
||||
Function output/returned: index of found substring, or
|
||||
SUBSTRING_NOT_FOUND constant
|
||||
if string not found
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
|
||||
/*
|
||||
Name: ???
|
||||
Process: ???
|
||||
Function input/parameters: ???
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: ???
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
|
||||
/*
|
||||
Name: ???
|
||||
Process: ???
|
||||
Function input/parameters: ???
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: ???
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
Dependencies: getStringLength
|
||||
*/
|
||||
int findSubString()
|
||||
{
|
||||
// return zero (temp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: strToLowerCase
|
||||
Process: iterates through string, sets any uppercase letter to lowercase
|
||||
equivalent, does not affect any letter with an upper/lower diff.
|
||||
Function input/parameters: c-style source string (char *)
|
||||
Function output/parameters: c-style dest string (char *)
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: toLowerCase
|
||||
*/
|
||||
void strToLowerCase()
|
||||
{
|
||||
// no return, void.
|
||||
}
|
||||
|
||||
/*
|
||||
Name: toLowerCase
|
||||
Process: sets character to lowercase letter if uppercase letter,
|
||||
returns character
|
||||
Function input/parameters: character input (char)
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: character output (char)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: none
|
||||
*/
|
||||
char toLowerCase()
|
||||
{
|
||||
// return null character (temp)
|
||||
return NULL_CHAR;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: getStringToDelimiter
|
||||
Process: captures a string from the input stream to a specified delimiter.
|
||||
will consume the delimiter.
|
||||
Function input/parameters: input stream (FILE *),
|
||||
stops at specified character
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringConstrained
|
||||
*/
|
||||
bool getStringToDelimiter(FILE *inStream, char delimiter, char *capString)
|
||||
{
|
||||
// return false (temp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: getStringConstrained
|
||||
Process: captures a string from the file stream with various constraints
|
||||
Function input/parameters: input stream (FILE *),
|
||||
clears leading non printable (bool),
|
||||
clears leading space (bool),
|
||||
stops at non printable (bool),
|
||||
stops at specified delimiter (char)
|
||||
will consume the delimiter.
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: fgetc
|
||||
*/
|
||||
bool getStringConstrained(FILE *inStream, bool clearLeadingNonPrintable,
|
||||
bool clearLeadingSpace, bool stopAtNonPrintable,
|
||||
char delimiter, char *capString)
|
||||
{
|
||||
// return false (temp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: getStringToLineEnd
|
||||
Process: captures a string from the input stream to the end of the line
|
||||
Function input/parameters: input file stream (FILE *)
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringConstrained
|
||||
*/
|
||||
bool getStringToLineEnd(FILE *inStream, char *capString)
|
||||
{
|
||||
// return false (temp)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: ???
|
||||
|
|
|
|||
|
|
@ -13,9 +13,52 @@
|
|||
|
||||
// function prototypes
|
||||
|
||||
/*
|
||||
Name: catString
|
||||
Process: concatenates two strings
|
||||
Function input/parameters: c-style string (char *)
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringLength
|
||||
*/
|
||||
void catString(char *outString, const char *inString);
|
||||
|
||||
/*
|
||||
Name: compareString
|
||||
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: c-style strings (char *) [first and second/left&right]
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: results as specfifed above (int)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringLength
|
||||
*/
|
||||
int compareString(const char *firstString, const char *secondString);
|
||||
|
||||
/*
|
||||
Name: copyString
|
||||
Process: copies string into new string variable, overwrites destination.
|
||||
Function input/parameters: c-style string (char *)
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringLength
|
||||
*/
|
||||
void copyString(char *outString, const char *inString);
|
||||
|
||||
/*
|
||||
Name: getStringLength
|
||||
Process: counts length of string from start to NULL_CHAR ('\0')
|
||||
Process: gets length of string from start to NULL_CHAR ('\0')
|
||||
Function input/parameters: c-style string (char *)
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: length of string (int)
|
||||
|
|
@ -23,6 +66,109 @@ Device input/---: NONE
|
|||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
int getStringLength(const char *stringLen);
|
||||
int getStringLength(const char *stringIn);
|
||||
|
||||
/*
|
||||
Name: getSubString
|
||||
Process: captures sub string within larger string
|
||||
between two inclusive indices.
|
||||
returns empty string if either index is out of range,
|
||||
assumes enough memory in dest string
|
||||
Function input/parameters: c-style string (char *)
|
||||
start and end indices (int)
|
||||
Function output/parameters: c-style destination string (char *)
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringLength, malloc, copyString, free
|
||||
*/
|
||||
void getSubString(char *destStr, const char *sourceStr,
|
||||
int startIndex, int endIndex);
|
||||
|
||||
/*
|
||||
Name: findSubString
|
||||
Process: linear search for given substring within another string
|
||||
Function input/parameters: c-style test string (char *),
|
||||
c-style source string (char *)
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: index of found substring, or
|
||||
SUBSTRING_NOT_FOUND constant
|
||||
if string not found
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringLength
|
||||
*/
|
||||
int findSubString();
|
||||
|
||||
/*
|
||||
Name: strToLowerCase
|
||||
Process: iterates through string, sets any uppercase letter to lowercase
|
||||
equivalent, does not affect any letter with an upper/lower diff.
|
||||
Function input/parameters: c-style source string (char *)
|
||||
Function output/parameters: c-style dest string (char *)
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: toLowerCase
|
||||
*/
|
||||
void strToLowerCase();
|
||||
|
||||
/*
|
||||
Name: toLowerCase
|
||||
Process: sets character to lowercase letter if uppercase letter,
|
||||
returns character
|
||||
Function input/parameters: character input (char)
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: character output (char)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: none
|
||||
*/
|
||||
char toLowerCase();
|
||||
|
||||
/*
|
||||
Name: getStringToDelimiter
|
||||
Process: captures a string from the input stream to a specified delimiter.
|
||||
will consume the delimiter.
|
||||
Function input/parameters: input stream (FILE *),
|
||||
stops at specified character
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringConstrained
|
||||
*/
|
||||
bool getStringToDelimiter(FILE *inStream, char delimiter, char *capString);
|
||||
|
||||
/*
|
||||
Name: getStringConstrained
|
||||
Process: captures a string from the file stream with various constraints
|
||||
Function input/parameters: input stream (FILE *),
|
||||
clears leading non printable (bool),
|
||||
clears leading space (bool),
|
||||
stops at non printable (bool),
|
||||
stops at specified delimiter (char)
|
||||
will consume the delimiter.
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: fgetc
|
||||
*/
|
||||
bool getStringConstrained(FILE *inStream, bool clearLeadingNonPrintable,
|
||||
bool clearLeadingSpace, bool stopAtNonPrintable,
|
||||
char delimiter, char *capString);
|
||||
|
||||
/*
|
||||
Name: getStringToLineEnd
|
||||
Process: captures a string from the input stream to the end of the line
|
||||
Function input/parameters: input file stream (FILE *)
|
||||
Function output/parameters: c-style string (char *)
|
||||
Function output/returned: success of operation (bool)
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: getStringConstrained
|
||||
*/
|
||||
bool getStringToLineEnd(FILE *inStream, char *capString);
|
||||
|
||||
#endif // STRINGUTILSPREP
|
||||
Loading…
Add table
Add a link
Reference in a new issue