[30]Chapter10 String Length

/*1.String Length
Write a function that returns an integer and accepts a pointer to a C-string as an argu-ment.  The  function  should  count  the  number  of  characters  in  the  string  and  return
that number. Demonstrate the function in a simple program that asks the user to input
a string, passes it to the function, and then displays the functions return value.*/

#include “stdafx.h”
#include<iostream>
#include<string>

using namespace std;

int stringCount(string);

int main()
{
string string;
cout<<“\nEnter string “;
cin>>string;
int count;
count=stringCount(string);

cout<<“\nThe number of characters in the string is “<<count<<” .\n”;

system(“pause”);
return 0;
}

int stringCount(string str)
{
int i=0;
int count=0;

while(str[i]!=”)
{
count++;
i++;
}
return count;
}