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

Recommended Answers

All 5 Replies

#include<iostream>
#include<string.h>

using namespace std;

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

  cout<<strlen(x);


 return 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...

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.

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;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.