Write a program that inputs a string value from the user and displays it in reverse using pointer.
#include <stdio.h>
#include <string.h>
void reverseing_string(char* s)
{
int len, x;
char *begin_pointer, *end_pointer, c;
len = strlen(s);
begin_pointer = s;
end_pointer = s;
for (x = 0; x < len - 1; x++)
end_pointer++;
for (x = 0; x < len / 2; x++) {
c = *end_pointer;
*end_pointer = *begin_pointer;
*begin_pointer = c;
begin_pointer++;
end_pointer--;
}
}
int main()
{
char str[100];
printf("Enter a string:\n");
scanf("%s",str);
reverseing_string(str);
printf("The reverse string is: %s\n", str);
return 0;
}
Comments
Leave a comment