66 lines
No EOL
1.8 KiB
C
66 lines
No EOL
1.8 KiB
C
// header files
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include "StandardConstants.h"
|
|
|
|
// constants
|
|
|
|
// function implementations
|
|
|
|
/*
|
|
Name: getStringLength
|
|
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)
|
|
Device input/---: NONE
|
|
Device output/---: NONE
|
|
Dependencies: included by standard libraries
|
|
*/
|
|
int getStringLength(const char *stringIn)
|
|
{
|
|
// define variables
|
|
int stringLength = 0, currentCharacter = 0;
|
|
// get user input (not needed)
|
|
// do calculations
|
|
while(currentCharacter < STD_STR_LEN && stringIn[currentCharacter] != NULL_CHAR)
|
|
{
|
|
// increment string length
|
|
stringLength = stringLength + 1;
|
|
// increment currentCharacter
|
|
currentCharacter = currentCharacter + 1;
|
|
}
|
|
// display results (not needed)
|
|
// return success
|
|
return stringLength;
|
|
}
|
|
|
|
/*
|
|
Name: main
|
|
Process: Runs all the functions listed above that was used as preparation for
|
|
CS480. Videos were used as the similar practice.
|
|
Function input/parameters: NONE
|
|
Function output/parameters: NONE
|
|
Function output/returned: NONE
|
|
Device input/---: NONE
|
|
Device output/---: NONE
|
|
Dependencies: included by standard libraries
|
|
*/
|
|
int main()
|
|
{
|
|
// define/initialize variables
|
|
int stringLen = 0;
|
|
char newString[] = "This is my new string!!!";
|
|
printf("\n---Phase 4: Getting String Length---\n");
|
|
printf("====================================\n");
|
|
// get user input
|
|
// do calculations
|
|
stringLen = getStringLength(newString);
|
|
// display results
|
|
printf("\nThe length of string '%s' is %d.\n", newString, stringLen);
|
|
printf("\nProgram End\n");
|
|
// return success
|
|
return 0;
|
|
} |