codescracker


c

C Program to Reverse String



« Previous Program Next Program »


Reverse String in C

To reverse string in C programming, you have to ask to the user to enter the string, now make a temp variable of char type and start reversing, place first character of the string in the temp and last character of the string in the first, then place temp in the last and so on

C Programming Code to Reverse String

Following C program ask to the user to enter a string to reverse it and display the reversed string on the screen:

/* C Program - Reverse String */
		
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	clrscr();
	char str[100], temp;
	int i=0, j;
	printf("Enter the String : ");
	gets(str);
	i=0;
	j=strlen(str)-1;
	while(i<j)
	{
		temp=str[i];
		str[i]=str[j];
		str[j]=temp;
		i++;
		j--;
	}
	printf("Reverse of the String = %s",str);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program to reverse string

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test