×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Accept a string and convert it in proper or Title case - String Initial of the name - String
Read string and convert it in Sentence case - String - String - C Language
1221    Arnab De    13/05/2019

Accept a string and convert it in Sentence case using C Language

Read a string from user using gets() function. Now travel the whole string and check it is an alphabet or Not. If it is an alphabet then check it position. If it is first character of the string and it is a small character [ASCII between 97 - 122], then convert it into upper case letter and other all charcter convert into lower case letter. Now check the others character of the string, if those characters are alphabets and capital letters [ASCII between 65 - 90], then convert it into small letter by adding 32 with it. Now print the string using puts().

int main()
{
	char str[30],i;
	//READ A STRING
	printf("Enter A String: ");
	gets(str);
	for(i=0;str[i]!='\0';i++)
	{
		if((str[i]>=65 && str[i]<=90) ||(str[i]>=97 && str[i]<=122))
		{
			if(i==0)
			{
				if(str[i]>=97 && str[i]<=122)
				{
					str[i]=str[i]-32;
				}
			}
			else
			{
				if(str[i]>=65 && str[i]<=90)
				{
					str[i]=str[i]+32;
				}
			}
		}
	}
	//PRINT THE OUTPUT
	printf("Result : ");
	puts(str);
	return 0;
}
Outputs

Enter A String: i am An Indian
Result : I am an indian

Accept a string and convert it in proper or Title case - String Initial of the name - 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.
Nelson Mandela
An educated, enlightened and informed population is one of the surest ways of promoting the health of a democracy.
Nelson Mandela
4038
40.91
Today So Far
Total View (Lakh)
softetechnologies
01/01/2018     34530
26/05/2018     32724
28/06/2017     31337
02/08/2017     29642
25/06/2018     27476
15/05/2017     24907
01/08/2017     24107
06/07/2017     23632
21/04/2018     19454
14/07/2017     19142
softetechnologies