The problem is in the strrevi function:Code:#include<stdio.h> #include<string.h> #include<conio.h> void strrevi(char *start,char *end) { char *temp; if((!start || !end)) return; for(;start<=end;start++,end--) { // printf("%c %c %c\n",*temp,*start,*end); temp=*start; *start=*end; *end=temp; // printf("%c %c %c\n",*temp,*start,*end); } } int main() { char string[20]="some text"; printf("%s\n",string); strrevi(string,string+strlen(string)-1); printf("%s",string); getch(); return 0; }
Why doesnt the program work properly if i use
char *temp in place of char temp and replace every instance of temp with *temp?
The commented lines may be uncommented for analysis purpose