Accept a string and convert it in upper case - String - C Language
softetechnologies
27-04-2019    398 times
string upper case C Language

Write a program to accept a string or name from the user and convert it into Upper case.

Read a string from user using gets(). Now travel the whole string and check it is an alphabet or Not. If it is an alphabet then check is it a lower case character [ASCII between 97 - 122], if it is a lower case character then substruct 32 from it and convert into upper case character. 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(str[i]>=97 && str[i]<=122)
			{
					str[i]=str[i]-32;
			}
		}
	}
	//PRINT THE OUTPUT
	printf("Result : ");
	puts(str);
	return 0;
}
Private Teacher
softetechnologies
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.
    Related Post
  Query About the post