Function in function does not work

To extract data using the EtherCard.h library, I use the “static void my_callback (byte status, word off, word only)” function.

I need to add another feature to this feature, but Arduino writes an error:
sketch_dec29a\sketch_dec29a.ino: In function ‘void my_callback(byte, word, word)’:
sketch_dec29a:20:3: error: a function-definition is not allowed here before ‘{’ token

Does anyone advise me how to modify the code so the features are working?

Thank you very much.

static void my_callback (byte status, word off, word len) {

Ethernet::buffer[off+len] = 0;
char* fullResponse;
fullResponse = (char*) Ethernet::buffer + off;
Serial.println(fullResponse);

String tmp = getValue(fullResponse,0);
String hum = getValue(fullResponse,1);
String prs = getValue(fullResponse,2);

String getValue(String data, int index)
{
int found = 0;
int strIndex = {0, -1};
int maxIndex = data.length()-1;

for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==’|’ || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}

return found>index ? data.substring(strIndex[0], strIndex[1]) : “”;
}

}

static void my_callback (byte status, word off, word len)

This defines the start of a function. The error message says you have not finished defining the loop function yet.

You can not define a function inside a function, if you think you have to then your thinking is wrong about how this language works. All function definitions must be separate. You can call a function from within a function and maybe that is what you intended to do, but only posting a snippet gives us no chance to see what you actually want to do.

Read the how to use this forum sticky post for advice on asking a question and posting code correctly.

Also defining a function to return a static void is just plain silly. Static means it persists from one call of the function to the next which doesn’t make any senses for a return variable of any type. But to make matters worse void means “nothing” that is, there is no variable to return, so I suppose a static void would a persistence nothing which makes no sense at all.

Grumpy_Mike:
Also defining a function to return a static void is just plain silly. Static means it persists from one call of the function to the next which doesn’t make any senses for a return variable of any type. But to make matters worse void means “nothing” that is, there is no variable to return, so I suppose a static void would a persistence nothing which makes no sense at all.

You need to review usage of C / C++ keywords. When applied to a function (void or otherwise), the purpose of 'static' is to limit its scope to the particular source file in which it appears. By default, functions have global scope across files.

The same is true for using 'static' with external (i.e. not defined within a function) variables. It limits their scope to the specific source file. Otherwise, they can be accessed by code in other source files (via the 'extern' keyword).

Since it is a best practice to limit variable / function as scope narrowly as possible, these uses of 'static' are useful in large, multi-file projects.

EDIT:
Reference K & R 'The C Programming Language', 2nd Edition, Section 4.6.

Live and learn. Thanks.

However I don’t think the OP is up to such subtitles.

You are trying to declare the function "String getValue(String data, int index)" inside the function "static void my_callback (byte status, word off, word len)". You can't put one function declaration inside another.