Hi everyone,
I was browsing through the forum to find some code for a palindrome program. I get some parts of it, but I'm confused what a certain while loop does. Can anyone help clarify?
char s[256],t[256]; /*char array of length 256*/
char *p,*q,*r; /*define char array*/
int i=0,j=0; /*initialize int i and j*/
printf("Please enter a word.\n"); /*print prompt*/
scanf("%s",s); /*read in string from the user*/
p=s+strlen(s)-1;
r=p;
while(i<strlen(s)){
t[i]=*p;
p--;
i++;}
q=s;
while(j<strlen(s)){
if(*r==*q){
r--;
q++;
j++;}
else {
break;
}
}
I put in some comments, but I would appreciate if anyone could point out errors in my understanding.
Thanks