string pallindrome

i am writing a program of string pallindrome, code is compiling successfully but on running it accepting the string but nothing after that, the output window stays on hold with cursor blinking, plz help what is wrong with this code.
i am using dev-c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h>

int main()
{
    char ch[20],c[20];
    int size,i,j;
    char *p;
    //char t;
   
       puts("enter the string");
    gets(ch);                 // the program stops here
   
    
    p=ch;
    
    while(ch!='\0')
    { p++;
      size++;
      }
      
      for(i=0,j=size-1;i<size/2;i++,j--)
      {
                //t=ch[i];
                c[i]=ch[j];
                //ch[j]=t;
                }
                
    for(i=0;i<20;i++)
    {
        if(c[i]==c[j])
        printf("string is pallindrome");
        
        else printf("string is not pallindrome");
        
        }
        
        
        getch();
        
        return 0;
        
        
        }

Last edited on
Can you see what's wrong here?

1
2
3
4
5
while(ch!='\0')
{
  p++;
  size++;
}


Andy

PS Please use code tags!

"How to use code tags"
http://www.cplusplus.com/articles/jEywvCM9/
i edited my post

what's wrong with the while loop, i am a beginner , help me
What is the value of ch?

Will it ever be '\0'? (which is a char with value 0).

Try cout << ch;

Andy
i understand now
i should have done
 
ch[size]!='\0'


thanks andy
Last edited on
And remember, variables are not automatically inititlized in C++ so if you expect size to start off at 0...

Andy

PS You're program doesn't look quite right (!) later on. For one thing, it's doing more work than needed (but I can sort of see the required logic is mostly there.)
Last edited on
Topic archived. No new replies allowed.