View Single Post
  #1 (permalink)  
Old 06-11-2008, 08:03 AM
rossen rossen is offline
Newbie
 
Join Date: Jun 2008
Posts: 4
Credits: 0
Rep Power: 0
rossen is on a distinguished road
Default C loop, giving me trouble !! Can anyone help..?

i have this code to test for palindromes, it functions perfectly well on the first test, but as the program continues to check for more after the first word it keeps printing not palindrome, once it wasnt the first word typed, run it pls, and you'll c what im talking about. Can anyone help me fix it..?

Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int isPalindrome( char *s);
int main (void)
{
int i=0;
int ch;
char s[100];
while (1){
while ((ch = getchar()) != ('\n')){
if (isalpha(ch)){
ch=toupper(ch);
s[i]=ch;
i++;
}
}
s[i]='\0';
if (isPalindrome(s) ==1){
printf("is palindrome\n");
}
else{
printf("not palindrome\n");
}
system("Pause");
return 0;
}
thanks,
-------------------------------------------

Last edited by v0id; 06-11-2008 at 09:13 AM.
Reply With Quote

Sponsored Links