I am doing some C programming at college.
This program should check if a word remains the same spelled backwards. (palindrome)
I am programming on a Mac, it compiles but always says it's not a palindrome. I asked a friend to compile on his Windows machine, it works for him.
It does work on my mac when i give a word of 1 character.
How is this possible?
Thanks in advance
Charlie
#include <stdio.h>
#include <string.h>
int isPalindroom(char *woord);
int main(int argc, char **argv) {
char woord[100];
printf("Give a word:" );
scanf("%s", woord);
if (isPalindroom(woord)) {
printf("Palindrome!\n");
} else {
printf("Not a palindrome\n");
}
return 0;
}
int isPalindroom(char *woord) {
//Vul aan
int i;
int lengte = strlen(woord);
if(lengte==0 || lengte==1) {
return 1;
} else {
if(woord[0]==woord[lengte-1]) {
/*for(i=0; i<lengte; i++) {
woord[i]= woord[i+1];
printf("%s\n", woord);
}
woord[lengte-2]= '\0';*/
woord[lengte-1]= '\0';
woord = woord + 1;
isPalindroom(woord);
} else {
return 0;
}
}
}


Sign In
Create Account

Back to top









