I'm trying to reverse a string using pointers.When i try to print the reversed string instead of getting DCBA i'm getting out only as BA?Can anyone help me on this?
#include<stdio.h>
void reverse(char *);
void main()
{
char str[5] = "ABCD";
reverse(str);
}
void reverse(char *str)
{
char *rev_str = str;
char temp;
while(*str)
str++;
--str;
while(rev_str < str)
{
temp = *rev_str;
*rev_str = *str;
*str = temp;
rev_str++;
str--;
}
printf("reversed string is %s",str);
}
stris pointing to at the time you callprintf