Use strlen() to get the length of a char array buffer : char array string « String « C++






Use strlen() to get the length of a char array buffer

  
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
   char buffer[80];
   do
   {
      cout << "Enter a string up to 80 characters: ";

      cin.getline(buffer,80);

      cout << "Your string is " << strlen(buffer);

      cout << " characters long." << endl;
   }while (strlen(buffer));
   return 0;
}
  
    
  








Related examples in the same category

1.Demonstrate the basic null-terminated string functions.
2.Operator pointer
3.Count spaces, punctuation, digits, and letters.
4.Convert char array to upper case
5.Using strcpy() to assign value from one char array to another char array
6.Using strncpy() to assign one char array to another char array
7.Using strcpy and string terminator
8.Using strncpy() and string terminator
9.Get the string length
10.Using strcat() and strncat().
11.Using atoi() function
12.Filling an Array