A Program to Reverse String
In this example, we are giving a program to reverse a string without the strrev() function.
Program to to reverse a string:
#include <stdio.h>
int main() {
char str[1000], rev[1000];
int start, end, count = 0;
printf("Input a string: ");
gets(str);
// calculating string length
while(str[count] != '\0')
count++;
end = count - 1;
for(start=0; start<count; start++) {
rev[start] = str[end];
end--;
}
rev[start] = '\0';
printf("Reverse of the string: %s\n",rev);
return 0;
}
Output:
Input a string: abc Reverse of the string: cba