Return of char function

Hi guys, i have problem. For example, i have char function like this:

char ShowName()
{
char text[255];
text = "Hi all";
return *text;
}

Ok, what is the problem ?

Try to print this function and you get ONLY first letter, not all of char text.
Please help me
You are returning a single character so it will print a single character.
If you want to print a string use a string
1
2
3
4
5
6
7
// #include<string> for string ( in namespace std )
string ShowName()
{
  string text;
  text = "Hi all";
  return text;
}
hm.. i know, but i want char more ....
Er... well if you want only a char, then use your original post. But it really sounds like you want a string.

char = 1 character
string = a sequence of multiple characters.

Also note that text = "Hi all"; won't even compile if text is a char array, but it will work just fine if text is a string.
fine, thanks
Actually, you are trying to work with cstrings in your first example, and your code pretty much shows you just didn't understand how cstrings work. For cstrings you normally use output parameters, because otherwise you'd have to reserve memory on the heap which the user would have to free later on.
Topic archived. No new replies allowed.