fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 10
  2. //
  3. /**************************************************************
  4.  * String length
  5.  *
  6.  * ____________________________________________________________
  7.  *This program will count the length of the entered string.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * Entered string.
  11.  * OUTPUT
  12.  * Length of the string.
  13.  **************************************************************/
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cmath>
  17. using namespace std;
  18. int stringLength(const char *str)
  19. {
  20. int length = 0;
  21. while (*str != '\0') {
  22. length++;
  23. str++;
  24. }
  25. return length;
  26. }
  27.  
  28. int main()
  29. {
  30. char inputString[100];
  31.  
  32. cout << "Enter a string: ";
  33. cin.getline(inputString, 100);
  34.  
  35. int length = stringLength(inputString);
  36.  
  37. cout << "The length of the string is: " << length << endl;
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty