// Saliha Babar CS1A #Chapter 10, #1, Page 588
//
/******************************************************************************
* CALCULATE STRING LENGTH
* ____________________________________________________________________________
* This function accepts a string up to n characters and then it calculates
* string length.
* ____________________________________________________________________________
* INPUT
* SIZE : size of the characters in string
* input : string entered by user
*
* OUTPUT
* strLength : length of the string
* ***************************************************************************/
#include <iostream>
#include <cstring>
using namespace std;
int CalcLength (char input[]);
int main() {
const int SIZE = 51; // INPUT - size of the characters in string
char input[SIZE]; // INPUT - array of characters
int strLength; // OUTPUT - string length
cout << "Enter a word/sentences up to " << SIZE - 1 << " characters long\n";
cin.getline (input, SIZE);
// Pass the input to the lengthfunc
strLength = CalcLength(input);
// Display the output
cout << "The string contains " << strLength << " characters.\n";
return 0;
}
int CalcLength (char input[])
{
int length;
length = strlen(input);
return length;
}