I am not sure why the following code isnt working.
I try to use gcc to compile it gcc -Wall -o test test.c
, it gives me warning message: control reaches end of non void function.
But I couldn't find the error so I tried to compile it ignoring the warning messages, and tested the program out using ./test 1234321
after compiling it using gcc -o test ispalidrome.c
But instead of returning 0 (that it should to my understanding because it didn't trigger any of the if statements to return 1), it returned a random value, 46, 52, 84 etc.
The main logic behind the program is exactly as required, I just can't tell why it isn't exiting properly.
#include <stdio.h>
int main(int argc, char **argv){
if (argc != 2){
fprintf(stderr, "Usage: %s \"string\"", argv[0]);
return 1;
}
else{
int i = 0;
while( '\0' != argv[1][i] ) i++;
char *start=argv[1];
char *end=&start[i-1];
while (start<end){
if (*start != *end){
break;
return 1;
}
printf("%c is the same as %c\n",*start, *end);
start =start+1;
end=end-1;
}
}
}