-
palindrome function
ok here is how i figure i would do it...
get input
determine lenght of string and reverse it bu looping a decreasing for loop and concatenating the strings into a second string
eg: text[100] added to reversedstring then text[99] added to reverstring and so on...
then i would use the strcmp function to test for equality and see if it is indeed a palindrome... is this the best way to do it? anyone else have some faster or better pseusocode also i dont know how to determine the lenght of a string :(
-
use strlen(string) for length
strcmp(str1,str2) for cmp
yeah its fast but more mem will be used
or you could use 2 loops one from 0 and incrementing and the other one from 99 and decrementing; comparing 0-99, 1-98 so on to see for palindrome.
-
This has been handled many times before, just click on this to see.
-Prelude
-
ok no i have a litle problem the uncommented lines i do not understand... what does tolower do?
Code:
char* start = text; //pass the whole array into the start variable
char* end = text + strlen(text) - 1; //pass the last charecter of the array into end
while(end > start)
{
if(tolower(*start) != tolower(*end))
{
return(0);
}
end--;
start++;
}
return(1);
-
tolower will return the upper case equivalent of the character that you pass to it.
-Prelude