Adding to what Shiro already said, when you name an array simply by it's name, you are actually accessing it's memory location.
So if you want to create a pointer to an array you write:
Code:
int* pmyarray = null; //declare and initialize array
int myarray[20] = {0}; //declares and initializes my array. All 20 elements are 0.
pmyarray = myarray; //assign myarray to the pointer
Notice that I didn't use the & operator on the last line exactly because 'myarray' alone already points to a memory location. The memory location of myarray[0]
Now to calculate your string lenght...
My prefered method is exactly by using pointers to arrays. Since a string is an array of chars...
Code:
bool CompareStrings(char string1[], char string2[])
{
char* pstring1 = string1;
char* pstring2 = string2;
long lenstring1 = 0; //for VERY large strings :P
long lenstring2 = 0;
while(*pstring1){
pstring1++;}
while(*pstring2){
pstring2++;}
lenstring1 = pstring1 - string1;
lenstring2 = pstring2 - string2;
if(lenstring1 != lenstring2) return FALSE;
//... include here your changed while loop
}
This warrants an explanation.
I start by declaring and initializing the pointers and the variables that will hold the strings lenght.
The while loop is a bit harder to explain. Since the pointers created point to arrays, they behave a little different then other pointers. When you add 1 to a pointer, you actually are telling the pointer to point to the next element of the array. Consider this:
pstring1 = string1 //point to element 1 of string1 (string1[0])
pstring1 = pstring1 + 1 //point to element 2 of string1 (string1[1])
pstring1 = pstring1 + 1 //point to element 3 of string1 (string1[2])
So the the while loop tests *pstring1 and checks if it is a value (a character) or the NULL character ('\0') that finishes all strings. If it is. it will stop. If it is not, it increments the pointer (pstring1++ is about the same as pstring1 = pstring1 + 1) and tests it's new position.
When the loop finishes, the pointer will be positioned at the last element of the array. Now you only need to get this last position memory address minus the first position (remember that an array name alone is actually the memory address of its first element) and you'll get the number of characters... aka, the size of the string in characters.
The last line is just a shortcut to avoid processing the remaining of your code. if the strings don't have equal lenght they are obviously not equal.
Just change the while loop on your own code to accomodate lenstring1 and add it after the return FALSE; statement above.