/********************************************************************************************
JM1206-2.cpp
Jim Millard
for CO211/Fall 1999
Program that finds the length of a c-style string
********************************************************************************************/
//included libraries
#include <iostream>
#include <string>
using namespace std;
//function prototypes
int lengthOf(const char[]);
//function definitions
int main()
{
const int maxelements = 31; //leave room for the NULL character!
char c_string[maxelements];
//inform and prompt the user
cout << endl
<< "This program will read a word (up to " << maxelements - 1
<< " characters) as input and" << endl
<< "return the its length." << endl;
//prompt and extract the string
cout << "Enter a word: ";
cin >> c_string;
//output the results
cout << endl
<< c_string << " is " << lengthOf(c_string) << " characters long." << endl;
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// Parses the array and returns the length of the zero-terminated string.
int lengthOf(const char s[])
{
//check the rest of the set
int i = 0;
while (s[i] != '\0')
i++;
return i;
}