I have written a function to check if two strings are same or not.
int sameString (char string1[], char string2[]) {
int i = 0;
while (string1[i] == string2[i]) {
if (string1[i] == "\0" || string2[i] == "\0") {
if (string1[i] == "\0" && string2[i] == "\0") {
return TRUE;
}
else {
return FALSE;
}
}
i++;
}
}
It is working correctly. But, gcc compiler is giving some warnings which I didn't get.
2.c: In function ‘sameString’:
2.c:10:24: warning: comparison between pointer and integer [enabled by default]
if (string1[i] == "\0" || string2[i] == "\0") {
^
2.c:10:46: warning: comparison between pointer and integer [enabled by default]
if (string1[i] == "\0" || string2[i] == "\0") {
^
2.c:11:28: warning: comparison between pointer and integer [enabled by default]
if (string1[i] == "\0" && string2[i] == "\0") {
^
2.c:11:50: warning: comparison between pointer and integer [enabled by default]
if (string1[i] == "\0" && string2[i] == "\0") {
^
Also while scanning and saving a string,
char operation[8];
scanf ("%s", &operation);
I am getting one more error, which I didn't get.
2.c: In function ‘main’:
2.c:65:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[8]’ [-Wformat=]
scanf ("%s", &operation);
^
Can someone explain what are these errors?