C Program to Reverse a String - C Program to Reverse String
Learn C - C tutorial - c program to reverse string - C examples - C programs
C Program to Reverse a String - C Program to Reverse String
- This program reverses a string that a user inputs.
- For example :If a user enters a string "wikitechy" then on reversing it will be "yhcetikiw"
Sample Code
#include<stdio.h>
#include<string.h>
int main()
{
char str[100]="wikitechy", temp;
int i, j = 0;
printf("\nThe string: wikitechy");
i = 0;
j = strlen(str) - 1;
while (i < j)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf("\nReverse string is :%s", str);
return (0);
}
Output
The string: wikitechy
Reverse string is :yhcetikiw