// Andres Guzman CSC5 Chapter 10, P. 588, #1
/******************************************************************************
*
* DISPLAY ESSAY LENGTH
* ____________________________________________________________________________
* Program will take entered sentence within essay and display the length of
* characters, including spaces, of sentence.
*
* Computation:
*
* Program will determine the length of the string using the "strlen" command
* from the cstring header.
* ____________________________________________________________________________
*
* INPUT
*
* SIZE = Size of Array
* sentence = Entered sentence
*
* OUTPUT
*
* length = Returned value of the function
*
******************************************************************************/
#include <iostream>
#include <cstring>
using namespace std;
int length(char *a);
int main()
{
const int SIZE = 1000;
char sentence[SIZE];
cout << "Please Enter a Sentence: ";
cin.getline(sentence, SIZE); //Gets entire line according to the size
//
//Outputs results with function call
cout << "\nString Length: " << length(sentence) << endl;
return 0;
}
/******************************************************************************
* Giving definition to function length. This function will add an integer value
* in accordance to the length of the c-string and to the variable length.
******************************************************************************/
int length(char *a)
{
int length = strlen(a); //Calculates characters before the null terminator
return length; //Returns the value
}