Finished General Utility

+- GeneralUtility.c
This commit is contained in:
Charles Descamps 2023-11-13 10:26:08 -07:00
parent 91ce50b189
commit 798858cf4e

View file

@ -28,8 +28,20 @@ Dependencies: privateGetStringLength
*/
int privateCompareStrings( const char *leftStr, const char *rightStr )
{
// return zero (temp)
return 0;
int diff, index = 0;
int leftStrLen = privateGetStringLen(leftStr);
int rightStrLen = privateGetStringLen(rightStr);
while (index < leftStrLen && index < rightStrLen)
{
diff = leftStr[index] - rightStr[index];
if (diff != 0)
{
return diff;
}
index = index + 1;
}
return leftStrLen - rightStrLen;
}
/*
@ -44,6 +56,17 @@ Dependencies: none
*/
void privateCopyString( char *dest, const char *source )
{
int characterCount = 0;
// use a while loop, check for !NULL_CHAR
while (source[characterCount] != NULL_CHAR)
{
// copy the character accessed into dest string
dest[characterCount] = source[characterCount];
// iterate the number of characters
characterCount = characterCount + 1;
}
// add a NULL_CHAR once done, characterCount is in the right place for \0
dest[characterCount] = NULL_CHAR;
// no return, void.
}
@ -59,8 +82,15 @@ Dependencies: none
*/
int privateGetStringLength( const char *str )
{
// return zero (temp)
return 0;
int strLen = 0;
// while through string until hit null.
while (str[strLen] != NULL_CHAR)
{
// increment the length string iterator
strLen = strLen + 1;
}
// return strLen
return strLen;
}
/*
@ -76,6 +106,11 @@ Dependencies: toPower (recursively)
*/
int privateToPower( int base, int exponent )
{
// return zero (temp)
return 0;
// if the exponent is 0, return one.
if(exponent == 0)
{
return 1;
}
// if not, then return base * privateToPower(base, exponent - 1)
return base * privateToPower(base, exponent - 1);
}