Problem Coding

Hello to all.
I have a problem in coding. :confused:
I want to create a function that returns 5 byte of char.
But I don't know how to do.
My wrong code is the same as below.
Please Help,thanks.

void loop()
{
	Serial.print(aaa());         
}

char aaa()
{
	char b[]={0};
	b[0]="H";
	b[1]="E";
	b[2]="L";
	b[3]="L";
	b[4]="O";
     return b;
}

Let's start with the obvious stuff.

char b[]={0};

How many elements are there in the b array ?

b[0]="H";

You should use single quotes to assign a value to a char

There is no terminating zero on the array so you cannot safely print it if that is what you want to do.

Try this

char b[6] = {0};  //allow room for the terminating zero

void setup()
{
  Serial.begin(115200);
  aaa(b);
  Serial.println(b);
}

void loop()
{
}

void aaa(char b[])
{
  b[0] = 'H';
  b[1] = 'E';
  b[2] = 'L';
  b[3] = 'L';
  b[4] = 'O';
  b[5] = '\0';
}

The function does not need to return a value because the array has been modified directly

I want to use this function in header and then use in main loop.
So how can I do with char b.

Show us a simple example of what you are trying to do.

The simplest thing is to use a global variable with enough space for the biggest word you want. For example

char myWord[21];

which has room for a 20 character word plus the terminating 0. It can also, of course, hold a 3 character word.

...R

Okay,
My real purpose is I wanna use Wire.read() function in another header, and it should return me Data.
And I want to use Data in my program.
That was my problem,
Thanks for taking your time.

leoncorleone:
That was my problem,
Thanks for taking your time.

I assume that means the problem is solved ?

...R

Dear Robin2
Sorry for my poor English.
I mean that is my problem.
What do you suggest?

leoncorleone:
What do you suggest?

I suggest you ask the Moderator to merge this Thread and your other Thread so that we can see all of the problem at the same time.

And I hope you have not created a THIRD thread about the same project ?

...R