// // Program: string_length // // Purpose: test function for finding length of a text // string. // // Input: // A text string. // Output: // The length of the string, not including the ending // null character. // // (This function is functionally equivalent to the library // function strlen().) // #include #include // has EXIT_SUCCESS #include // has setw() // Function to compute length of a text string. // Pre: s contains a null-terminated text string. // Post: length of s (number of characters up to but not // including null character) is returned. int length(char s[]) { int l = 0; while (s[l] != '\0') ++l; return l; } // Main program. int main(void) { const int BUFFSIZE = 1000; char aString[BUFFSIZE]; cout << "Enter a text string: "; cin >> setw(BUFFSIZE) >> aString; cout << "The length of " << aString << " is " << length(aString) << endl; return EXIT_SUCCESS; }