WhizRx interview question

reverse the words in the string

Interview Answer

Anonymous

26 Jul 2012

#include #include void main() { char *p1,*p2; int i,len=0,j; clrscr(); printf("\n enter a string:"); scanf("%s",p1); i=0; while(*(p1+i)!='\0') { i++; len++; } i=len-1; j=0; while(i>=0) { *(p2+j)=*(p1+i); j++; i--; } *(p2+j)='\0'; i=0; printf("\n The reversed string is:"); while(*(p2+i)!='\0') { printf("%c",*(p2+i)); i++; } getch(); }