char declaration problem

I'm trying to write function that will return me a value of variable passed by GET or POST but got problems declaring char variable.
Every variable identification will be two chars long ex. &ac=
Every variable value will be max ten chars long

I was debuging and debuging and as you can see below if I declare char like this:

char mth[] = "00";

Everything works fine and Serial output is like this:

&ac=ulogin&lg=qwe&ps=123
l0
lg
14

And it's OK output is just like it should be but if i declare char like this:

 char mth[2]; //or
 char mth[2] = {'\0', '\0'};//or
 char mth[2] = {'a', 'a'} ;

Serial prints some odd characters and algorithm just don't work thanks to those strange extra characters:

&ac=ulogin&lg=qwe&ps=123
la
#h
lg
#h
0

My test code:

void setup() {                
   Serial.begin(9600);

   char *st = "&ac=ulogin&lg=qwe&ps=123"; //some http var string for tests
   findVarIndex(st, "lg");    //calling to search for &lg value
}

void loop() {
 
}

int findVarIndex(char *str, char *sfind) {
  int fn = 0;
  int in = 0;
  char mth[] = "aa"; //<= core of the problem
  Serial.println(str);
   for(int i = 0; i < strlen(str); i++) {
     if(str[i] == '&') {
       for(int n = 0; n < strlen(sfind); n++) {
          if(str[i+(n+1)] == sfind[n]) {
            if(in < 2) {
              mth[in] = str[i+(n+1)];
              in++;
            }
            Serial.println(mth);
            if(!strcmp(mth, sfind)) {
              if(str[i+(n+1)+1] == '=') {
                fn = (i+(n+1)+2);
	        break;
              }
            }
          }
       }
     } 
   }
   Serial.println(fn);
   return fn;
}

I'm really thank full for any advice, I'm sure I just don't know something about char arrays in arduino.

char mth[] = "00";

That is a three element array.
It has two '0' characters and an implied '\0' terminator character, and is a C string.

char mth[2] = {'a', 'a'} ;

That is a two element array. It has no '\0' terminator character and is not a C string.

You are right i declared like this now:

char mth[3];

And it works perfect, hah I used standard approach from other languages where array that has two elements would be 2 element array :stuck_out_tongue:

What exactly is this '\0' terminator character (or where I can read about it thanks) I thought that this is used to allocate empty space. BIG BIG thanks for help I was fighting with this all yesterday afternoon.

What exactly is this '\0' terminator character (or where I can read about it thanks)

Google "NULL terminated C string".

C strings have a zero character (the terminator, written '\0') as the last element.
So, a string-handling function like "strlen" (string length) is passed the address of the first character in the string.
All "strlen" has to do then is increment the pointer and count until it reaches a zero character (which may not necessarily the end of the array as it was declared.)

char fox [] = "The quick brown fox";
int len = strlen (fox);
...
Serial.print (len); // shows 19 
...
fox [4] ='\0'; //"prematurely" terminate the string
 len = strlen (fox);
Serial.print (len); // shows 4
Serial.print (fox); // shows "The "