0

I wanna know how 2 return string by using function for example if we want to check the lenght of string we use cout<<strlen("c") but how to use this by fuction

5
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by webs1987
0
#include<iostream>
#include<string.h>

using namespace std;

int main()
{
  char x[] = {"hello"};

  cout<<strlen(x);


 return 0;
}
0

Use C++ string, they are better, and more stable.

C-strings have been around a lot longer than the C++ string class -- therefore they are quite stable...

0

C-strings have been around a lot longer than the C++ string class -- therefore they are quite stable...

Yes, they have been a lot longer out there, but I'm not at all a big fan of NULL terminated strings.

0

I wanna know how 2 return string by using function for example if we want to check the lenght of string we use cout<<strlen("c") but how to use this by fuction

int stringLength(char *s)
{
int a = 0;
while(*s!='/0')
{
a++;
}
//string length given in a
return a;
}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.