Error by return value

I wanted to store the header of the website as a string and retrieve when needed. But the Arduino IDE return an error message:

myproject.cpp: In function 'void getHtmlHeader()':
html:96: error: return-statement with a value, in function returning 'void'

Here is the function:

void getHtmlHeader() {
	
	String html = " "
	"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
	"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
	"<head>\n"
	"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
	"<link href=\"/FAVICON.ICO\" rel=\"shortcut icon\" type=\"image/x-icon\" />\n"
	"<link rel=\"stylesheet\" href=\"/STYLE.CSS\" type=\"text/css\" />\n"
	"<title>Arduino</title>\n"
	"</head><body>\n"
	"\n";
	
	return (html);
}

And then the function is called:

String html = getHtmlHeader();

The long string is no problem here. But what am I doing wrong?

you must declare the function not to return void but to return string;

String getHtmlHeader() 
{
	String html = " "
	"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
	"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
	"<head>\n"
	"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
	"<link href=\"/FAVICON.ICO\" rel=\"shortcut icon\" type=\"image/x-icon\" />\n"
	"<link rel=\"stylesheet\" href=\"/STYLE.CSS\" type=\"text/css\" />\n"
	"<title>Arduino</title>\n"
	"</head><body>\n"
	"\n";
	
	return (html);
}

But be aware that String usage can be RAM expensive, so you do some research on how to use PROGMEM or place the static strings in EEPROM or on an SD card …

robtillaart: you must declare the function not to return void but to return string;

... and how do I do that?

look care fully at the differences in my post and your post …

Hint: I changed void to String in one place

I make the string called "html" and try to return it. In other features the same string and I have no problems. my problem is basically to return the string.

Now I understand ... My program consists of several files, the function will probably not be invoked by the compiler at the right time.

Void means nothing, so if you say to the compiler that your function will not return nothing and then in the end you say that you want to return a String the compiler will give you an error. But doing that you will run out of ram as pointed out.

you must declare the function not to return void but to return string;

String getHtmlHeader() 
{
    String html = " ";
        // Snip happens
        return html;
}

This really won't work. html is a local variable. It goes out of scope when the function ends. Now, the caller has the address of out-of-scope memory where the data was stored. That memory may be overwritten at any time, with any other type of data.

void getHtmlHeader(String &html)
{
   html = " ";
   // Snip happens
}

called like so:

String html;
getHtmlHeader(html);

works much better, since the caller owns the memory space that the function is writing to.

The downside is that the IDE doesn't correctly create function prototypes for functions with reference variables, but it is not hard to create the required prototype:

void getHtmlHeader(String &html);

Put this before the setup() function.