sizeof() function giving strange results

This probably falls squarely under NOOB, but I just cant’t figure it out. I have function that is supposed to compare strings. It takes two strings in, and if the start of the string being compared is the same as the reference string, it returns true, false otherwise. Here is the function with debugging Serial.prints:

boolean StringStartsWith(char *stringToCompare, char *referenceString){

Serial.print("String to compare: ");
delay(100);
Serial.println(stringToCompare);
delay(100);
Serial.print("sizeof(stringToCompare): ");
delay(100);
Serial.println(sizeof(stringToCompare));
delay(100);
Serial.print("Reference string: ");
delay(100);
Serial.println(referenceString);
delay(100);
Serial.print("sizeof(referenceString): ");
delay(100);
Serial.println(sizeof(referenceString));

for (byte i=0; i < sizeof(referenceString); i++){
Serial.print(stringToCompare*);*

  • delay(100);*
  • Serial.print(’=’);*
  • delay(100);*
    _ Serial.println(referenceString*);_
    _
    delay(200);_
    if (stringToCompare _!= referenceString){
    return false;
    }
    }
    return true;
    }
    [/quote]*

    Below is the output from the Serial.prints. The strings are intact, but sizeof() always returns ‘2’, even though they are neither the same size, or indeed size ‘2’. So, what gives?_

*_</em></em> <em><em><em>*String to compare: TEMP=20 sizeof(stringToCompare): 2 Reference string: TEMP? sizeof(referenceString): 2 T=T E=E*</em></em></em> <em><em>_*

I think it's telling you that the size of pointers on the Atmega is 2 - stringToCompare is a pointer to characters (that's what char * means). You probably want strlen instead.

Andrew