fork download
  1. //Andrew Alspaugh CS1A Chapter 10. P. 588. #1
  2. //
  3. /****************************************************************************
  4. Determine String Length
  5. _____________________________________________________________________________
  6. This program displays a user entered string (up to 25 characters) and
  7. displays the total amount of characters the user inputed.
  8. ____________________________________________________________________________
  9. //Input
  10. const int SIZE = 26;
  11. char string [SIZE];
  12.  
  13. //Output
  14. int length;
  15. ****************************************************************************/
  16. #include <iostream>
  17. #include <cstring>
  18. using namespace std;
  19.  
  20. //Get Length Function Using a Pointer
  21. int GetLength (char *string, const int SIZE);
  22.  
  23. int main()
  24.  
  25. {
  26. //DATA DICTIONARY
  27.  
  28. //Input
  29. const int SIZE = 26;
  30. char string [SIZE];
  31.  
  32. //Output
  33. int length;
  34.  
  35. //INPUT
  36.  
  37. //Input string up to 25 characters (25 just for purpose of this program)
  38. cin.getline (string, SIZE);
  39.  
  40. //PROCESS
  41.  
  42. //Call Function to Determine Length
  43. length = GetLength (string, SIZE);
  44.  
  45. //OUTPUT
  46.  
  47. //Output String
  48. cout << "You entered the following string:" << endl;
  49. cout << string << endl << endl;
  50.  
  51. //Output Length
  52. cout << "The string you entered has " << length << " characters" << endl;
  53.  
  54. return 0;
  55. }
  56.  
  57. //Get Length Definition
  58. int GetLength (char *string, const int SIZE)
  59. {
  60. return strlen (string);
  61. }
Success #stdin #stdout 0.01s 5320KB
stdin
random string ig...
stdout
You entered the following string:
random string ig...

The string you entered has 19 characters