×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Find the frequency of character in a sentence - String
Reverse a string - String - String - C Language
2320    Arnab De    15/04/2019

Write a C program to reverse a string

calculate the length of the string. Copy the characters of the string into another string from the back or in reverse order. We can also use strrev() method to reverse the string. for that, we must include string.h header file.

softetechnologies
#include<string.h>

int main()
{
	char str[30],rev[30],j,i,l;
	printf("Enter A String: ");
	gets(str);
	l=strlen(str);
	for(i=0,j=l-1;j>=0;i++,j--)
	{
		rev[i]=str[j];
	}
	rev[i]='\0';
	printf("Reverse String Is ");
	puts(rev);
	return 0;
}
softetechnologies

Rewrite the same program using strrev() method

#include<string.h>

int main()
{
	char str[30],rev[30],j,i,l;
	printf("Enter A String: ");
	gets(str);
	strrev(str);
	printf("Reverse String Is ");
	puts(str);
	return 0;
}
softetechnologies
Find the frequency of character in a sentence - String
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
Fill the brain with high thoughts, highest idrals, place them day and night before you, and out of that will come great work.
Swami Vivekananda
2895
82.78
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54460
25/06/2018     45529
01/01/2018     43905
28/06/2017     41418
02/08/2017     40486
01/08/2017     34493
06/07/2017     34274
15/05/2017     33513
11/09/2018     30754
14/07/2017     30254
softetechnologies