int is_palindrome(MY_STRING palindrome);
int main(int argc, char* argv[])
{
char ch = 1;
MY_STRING palindrome = my_string_init_default();
while (1) {
///this puts in the line from the keyboard input to the data structure character by character
ch = getc(stdin);
if (ch == '\n' || ch == EOF)
break;
palindrome->push_back(palindrome, ch);
}
if (is_palindrome(palindrome)) {
printf("Yes \n");
}
else {
printf("No \n");
}
return 0;
}
int is_palindrome(MY_STRING palindrome) {
int i,flag;
MY_STRING temp = my_string_init_default();
MY_STRING reversed = my_string_init_default();
int size = palindrome->get_size(palindrome);
//removes all non-alphabetical characters
for (i = 0; i <= size-1; i++){
if (isalpha(palindrome->at(palindrome, i))) {
temp->push_back(temp, tolower(palindrome->at(palindrome,i)));
}
}
size = temp->get_size(temp);
for (i = size - 1; i >= 0; i--) {
reversed->push_back(reversed, temp->at(temp, i));
}
/checks to see if the reversed string above is equal to the original
for (flag = 1, i = 0; i < size; i++)
{
if (reversed->at(reversed,i) != temp->at(temp,i))
flag = 0;
}
if (flag == 0) {
return 1;
}
return 0;
}
the data structure am using MY_sTRING is assumed to work just fine. is there a problem for any part of the code am using. I think its one of the loops or one of the conditional statements
am getting this assertion c>=0 and c<=255. I don't exactly understand what that error means.
Aucun commentaire:
Enregistrer un commentaire