CONVERSION FROM UPPERCASE TO LOWER CASE USING C PROGRAM




Conversion from uppercase to lower case using c program

#include<stdio.h>
#include<string.h>
int main(){
  char str[20];
  int i;
  printf("Enter any string->");
  scanf("%s",str);
  printf("The string is->%s",str);
  for(i=0;i<=strlen(str);i++){
      if(str[i]>=65&&str[i]<=90)
       str[i]=str[i]+32;
  }
  printf("\nThe string in lower case is->%s",str);
  return 0;
}

Algorithm:

ASCII value of 'A' is 65 while 'a' is 97. Difference between them is 97 – 65 = 32
So if we will add 32 in the ASCII value of 'A' then it will be 'a' and if will we subtract 32 in ASCII value of 'a' it will be 'A'. It is true for all alphabets.
In general rule:
Upper case character = Lower case character – 32
Lower case character = Upper case character + 32





3. Write a c program to delete the all consonants from given string.

49 comments:

Krishna said...

HI..this program is not giving any output..
plz check it

Anonymous said...

You have to include the header file coz string functions are being used.

Anonymous said...

need fflush(stdin) n getchar() there.. n change into lower case right? please make a correction..

chintamani said...

hey this programm is not returning upper case .please correct it..

Ritesh kumar said...

This program doesn't convert into upper case while it converts only uppercase to lower case

Anonymous said...

scanf statement does not contain &

Anonymous said...

Hey! This doesn't convert lower case to upper case, it only convert upper case to lower case.please check it.

karunakar said...

HEY!this programm is not returning upper case .please correct it..

Anonymous said...

Hi ! What would be the program without using function strlen.

anusha said...

Hy!I think this program is not correct.Please check it once.

Anonymous said...

the correct program is this without any error:-

#include
#include
int main(){
char str[20];
int i;
printf("Enter any string->");
scanf("%s",&str);
printf("The string is->%s",str);
for(i=0;i<=strlen(str);i++){
if(str[i]>=65&&str[i]<=90)
str[i]=str[i]+32;
}
printf("\nThe string in uppercase is->%s",str);
return 0;
}

Anonymous said...

dont we have to use fflush(stdin) when we accept string????

rocking said...

inside the scnaf & then . it also not work.
pls check it again.

ram said...

create a function to change the case of alphebet

ram said...

create a function to find factorial of anumber

ram said...

create a function to the area of a triangle

Mur said...

Guys, It will just convert from Upper case to lower case !!! everything works perfectly

Anonymous said...

Hope you don't mind, but I added to the program to do both upper and lower case.

#include

int main(void){
char str[20];//intitializes string
int i = 0;

printf("Enter any letter");//asks for a letter

scanf("%s",&str);//scans for a letter

for(i=0;i<=20;i++)//for loop that continues to the last character of the string
{
if(str[i]>=65&&str[i]<=90)//if uppercase
str[i]=str[i]+32;//adds to character to change lower case

else if(str[i]>=97&&str[i]<+122)//if lowercase
str[i]=str[i]-32;//subtracts to change to uppercase
}
printf("\nThe opposite letter is->%s\n",str);//outputs the opposite letter
return (0);
}

Anonymous said...

no problem in the code.
The statement in the final printf() should be "\nThe converted string in lower case is %s" so that the logic is correct :)

Anonymous said...

thanks boss i want this program only it works perfectly

Anonymous said...

What is the output of:
main()
{
printf(5+"Good Morning");
}

Neha Sharma said...

5GoodMorning

Neha Sharma said...

if we do string concatenation using + operator then both operands of + operator should be a string . so it make a whole string because here 5 which is an integer has been converted into string

Gourav Sarkar said...

its not working

Teshan Ds said...

#include
#include
#include

int main()
{
char s[20],i=0;

printf("\nEnter word : ");
scanf("%s",s);

for(i;i==0;i++)
{
if(97<=s[i]<=122)
s[i]=s[i]-32;
}
printf("\n Anwser : %s",s);
getch();
}

Teshan Ds said...

1st character in to upper case

Fenal said...

This is a very good website. Just need a c prog for following design.
If n=5 then the o|p must be:
11111
12221
12321
12221
11111

Suraj said...

there is one change
There is(strlen)rough it and take it to n[i]

Utsav Upadhyay said...

Hey guys, My Qu. is "Convert the case of a given character ( i.e. upper to lower & vice versa ) ( Use getchar & putchar )", and this prog.showing 4 errors and I don't knw how to get rid of... Help me about this prog.????
Note: I must have to solve this prog.using "getchar" and "putchar"

#include
void main()
{
char ch;
getchar(ch);
if(getchar(char)(lowercase(ch)))
{
putchar((char)uppercase(ch));
}
else if(getchar((char)uppercase(ch)))
{
putchar((char)lowercase(ch));
}
}
}

Emerge Paul Faller said...

you can change it again in from Lower to Upper if you subtract it again in 32 or (-32)... since the upper to lower is (+32).

Anonymous said...

Morning

M Saif Ul islam Bhatti said...

simply use build in function toupper of ctype library;

Sharjeel Khan said...

why morning..?plz explain

Manjunath Bilwar said...

Nice article

Karthik Reddy said...

its just like string pointer as in if s[15]="Good Morning" then puts(s+5) will print Morning.

tanzib007 said...

there should be an equal sign instead of plus (+) sign in this line else if(str[i]>=97&&str[i]<+122)//if lowercase

prajakta sudake said...

hi...........this program is not run

rehan saiyad said...

& isn,t require for scan string
scanf("%s",str); //correct

ODko Geon said...

Thanks works perfectly.

Thulung D Danesh said...

we never use & when scanning array because it is already a pointer.

rishab said...

#include
int main()
{char ch;
scanf("%c",&ch);
if(ch>='a'&&ch<='z')
{ch=ch-'a'+'A';}
printf("%c\n",ch);}

rishab said...

#include
int main()
{char ch;
scanf("%c",&ch);
if(ch>='a'&&ch<='z')
{ch=ch-'a'+'A';}
printf("%c\n",ch);}

rishab said...

#include
int main()
{char ch;
scanf("%c",&ch);
if(ch>='a'&&ch<='z')
{ch=ch-'a'+'A';}
printf("%c\n",ch);}

Shreeju Dhakal said...

#include
int getfactorial (int n);
int main()
{
int num,fact;
printf("enter a number:");
scanf("%d",&num);
fact=getfactorial(num);
printf("the factorial of %d is %d",num,fact);
return 0;
}
int getfactorial (int n)
{
int i,sum=1;
for(i=1;i<=n;i++)
sum=sum*i;
return sum;
}

Shreeju Dhakal said...

write afunction"covertcase()" which converts the lower case letters in the string to uppercase where the main function displays the final string to the user? :)

Tuntun Kumar said...

678
123
049
write a c program to which will give o/p as 678394012

Unknown said...

good

Unknown said...

whats is 32..

vaddi kasulu madu said...

hi guys This program doesn't convert into upper case lower case y bocz it depends on compilation dependent..