Finished General Utility
+- GeneralUtility.c
This commit is contained in:
parent
91ce50b189
commit
798858cf4e
1 changed files with 41 additions and 6 deletions
|
|
@ -28,8 +28,20 @@ Dependencies: privateGetStringLength
|
||||||
*/
|
*/
|
||||||
int privateCompareStrings( const char *leftStr, const char *rightStr )
|
int privateCompareStrings( const char *leftStr, const char *rightStr )
|
||||||
{
|
{
|
||||||
// return zero (temp)
|
int diff, index = 0;
|
||||||
return 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 )
|
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.
|
// no return, void.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,8 +82,15 @@ Dependencies: none
|
||||||
*/
|
*/
|
||||||
int privateGetStringLength( const char *str )
|
int privateGetStringLength( const char *str )
|
||||||
{
|
{
|
||||||
// return zero (temp)
|
int strLen = 0;
|
||||||
return 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 )
|
int privateToPower( int base, int exponent )
|
||||||
{
|
{
|
||||||
// return zero (temp)
|
// if the exponent is 0, return one.
|
||||||
return 0;
|
if(exponent == 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// if not, then return base * privateToPower(base, exponent - 1)
|
||||||
|
return base * privateToPower(base, exponent - 1);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue