Monday, 30 April 2012

Calculate the length of a String in C++


#include <iostream>

using namespace std;

int length(char*);

int main()
{
  char line[81];
  cout << "Enter a array of characters:" << endl;
  cin.getarray(array,81);
  cout << endl;
  cout << "The string you entered has " << length(array)
       << " characters" << endl;
  return 0;
}     
getarray(array[],n)
{
  int length = 0;
  while (*chptr != '\0')
  {
    ++length;
    ++chptr;
  }
  return length;
}      

No comments:

Post a Comment