// Elaine Torrez CS1A
// _____________________________________________
//
// MEASURE STRING LENGTH
// _____________________________________________
// This program prompts the user to enter a string
// and determines the number of characters in the
// string. The program then displays that number.
// _____________________________________________
// INPUT
// userStr : The string entered by the user
//
// OUTPUT
// length : Number of characters in the string
// _____________________________________________
#include <iostream>
using namespace std;
// FUNCTION PROTOTYPE
int strLength(const char *str);
int main()
{
/**********************************************
* VARIABLE DECLARATIONS
**********************************************/
const int SIZE = 100;
char userStr[SIZE]; // INPUT string
int length; // OUTPUT string length
/**********************************************
* INPUT
**********************************************/
cout << "Enter a string: ";
cin.getline(userStr, SIZE);
/**********************************************
* PROCESS
**********************************************/
length = strLength(userStr);
/**********************************************
* OUTPUT
**********************************************/
cout << "\nString length: " << length << endl;
return 0;
}
// ************************************************
// strLength
// ------------------------------------------------
// Returns the number of characters in a C-string.
// ************************************************
int strLength(const char *str)
{
int count = 0;
while (str[count] != '\0')
count++;
return count;
}