// Diego Martinez                         CSC5              Chapter 10, P.588,#1
/*******************************************************************************
* DISPLAY STRING LENGTH
* ______________________________________________________________________________
* This program asks the user to enter a string. A function is used to count
* the number of characters in the C-string and return the length of the string.
*
* Computation is based on the Formula:
*
*      length = number of characters before the null terminator ('\0')
*
* ______________________________________________________________________________
* INPUT
*
*      User string
*
* OUTPUT
*
*      Length of the string
*
*******************************************************************************/

#include <iostream>
#include <cstring>
using namespace std;

// Function prototype
int stringLength(const char *);

int main()
{
    // Variable declaration
    char userString[100];
    int length;

    // User input
    cout << "Enter a string: ";
    cin.getline(userString, 100);

    // Function call
    length = stringLength(userString);

    // Output result
    cout << "The length of the string is: " << length << endl;

    return 0;
}

// Function definition
int stringLength(const char *str)
{
    int count = 0;

    // Count characters until null terminator
    while (*(str + count) != '\0')
    {
        count++;
    }

    return count;
}