In this c program we are reversing a string without using library function( Strrev). we are using a temporary variable store for reversing the string.
#include<stdio.h>
#include<string.h>
int main() {
char str[100], store ;
int i, j = 0;
printf("\nEnter the string :");
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j) {
store= str[i]; //the value at index i will be stored in store variable.
str[i] = str[j]; // the value at index j will be stored in index i.
str[j] = store; // the value of store variable will be stored in index j
i++; // incrementing value of i by one.
j--; // decrementing value of j by one.
}
printf("\nReverse string is :%s", str);
return (0);
}
OUTPUT
Enter the string : Suresh
Reverse string is :hseruS
0 Comment(s)