strcmp() is not a "method" , it's a standard C function, have some respect.
Methods are for cool boarders, and .NET'ers.
Here are some ideas to kick around:
Code:
/*Yes , well a string is in a character array right? eg: */
#include <stdio.h>
int main(void)
{
int i;
char s1[] = "Hello";
char s2[] = { 'H', 'e', 'l', 'l', 'o', '\0', '\0', '\0' };
/*
Strings defined in double quotes are automatically appended with the null character: '\0' (zero).
The string declarations above stored identically except that s2 will be two bytes larger.
Their "sizes" are 6 and 8 respectively but their string lengths are both 5.
*/
printf("sizes: s1: %u s2: %u \n\n", sizeof(s1), sizeof(s2) );
/*
We "index" (number) the string characters, like any array, starting with zero.
So you could make a loop and print the characters from index 0 until you run into the '\0':
*/
for ( i= 0; i < (int)sizeof(s2); i++ )
{
printf("s2[%d] = %c %02x \n", i, s2[i], s2[i]);
}
putchar('\n');
/* We could also make a loop to print the same index of both s1 and s2: */
for ( i= 0; ; i++ )
{
/* stop when the first \0 of either string is encountered */
if ( s1[i] == '\0' || s2[i] == '\0' )
{
break;
}
printf("s1[%d] = %c %02x , s1[%d] = %c %02x \n",
i, s1[i], s1[i], i, s2[i], s2[i] );
}
printf("\nThe shorter string's length is: %d \n", i );
printf("\nIt doesn't take too much imagination to see how the second loop \n\
could be used to compare two strings and calculate a meaningful value. \n\n\
...and from there taken to a function that returns a meaningful value! \n");
return 0;
}
/***** output : ********************
sizes: s1: 6 s2: 8
s2[0] = H 48
s2[1] = e 65
s2[2] = l 6c
s2[3] = l 6c
s2[4] = o 6f
s2[5] = 00
s2[6] = 00
s2[7] = 00
s1[0] = H 48 , s1[0] = H 48
s1[1] = e 65 , s1[1] = e 65
s1[2] = l 6c , s1[2] = l 6c
s1[3] = l 6c , s1[3] = l 6c
s1[4] = o 6f , s1[4] = o 6f
The shorter string's length is: 5
***********************************/
Now try fooling around with the characters is s1 and s2....
And yes you should look up strcmp(). Here is a nice C reference: :The C Library Reference Guide
And NOWHERE in there are "methods" mentioned !!! whippersnappers!