I have an assignment where i have to make a palindrome program. As you can see i have already done the basic palindrome prog, however i am now stuck since the program goes into a infinite loop whenever a word with whitespaces is added.
I have also tried searching for methods online however they do not seem to work for me...
I don't see how that for-loop will go into an infinite loop but I did see a problem with one of your if-statements:
if (palin[i] == ' ') Should be if (palin[i] == " ")
The way you were doing it, it will be checking the ascii value of the (' ') character which is 32 and since that is not what you want, you will never get a match there.
Also since you are looking for a palindrome, checking for matching letters every time in the for-loop is not a good idea because you could get false positives.
ex. if you have the string:
whaagw
With the way your code is set up, it will say that that string is a palindrome when clearly it is not. So what you should be checking for instead is if the characters on either end do not match and when this is true, you should break out of the for loop and return false.
if (palin[i] == ' ') Should be if (palin[i] == " ")
The way you were doing it, it will be checking the ascii value of the (' ') character which is 32 and since that is not what you want, you will never get a match there.
The if condition was correct. palin[i] is a char. ' ' is a char. " " is not. The body of code executed when the if is entered is not correct, however. And both indices should be checked for spaces.