//Sam Partovi CS1A Ch. 10, P.588, #1
/*******************************************************************************
* DETERMINE STRING LENGTH
* ____________________________________________________________
* This program accepts a given string and determines the length, in characters.
* The program then returns the number of characters present in the string.
* ____________________________________________________________
* INPUT
* ARRAY_SIZE: Size of string array
* string: Given string to determine length
* OUTPUT
* stringLength: Length of given string in characters
*******************************************************************************/
#include <iostream>
#include <cstring>
using namespace std;
//Function prototype for DetermineLength
int DetermineLength(char string[]);
int main() {
const int ARRAY_SIZE = 51; //INPUT - Size of string array
char string[ARRAY_SIZE]; //INPUT - Given string to determine length
int stringLength; //OUTPUT - Length of given string in characters
//Prompt for given string
cout << "Enter a string up to " << ARRAY_SIZE - 1 << " characters: ";
cin.getline(string, ARRAY_SIZE);
//Call DetermineLength function and assign returned value to stringLength
stringLength = DetermineLength(string);
//Display the result of string length
cout << "\nThe string is " << stringLength << " characters long.";
return 0;
}
//******************************************************************************
//Function definition for DetermineLength:
// This function accepts a given string and returns the value of the string
// length, in characters.
//*****************************************************************************/
int DetermineLength(char string[]) {
return strlen(string);
}