Write a c program to convert the string from lower case to upper case






Write a c program to convert the string from lower case to upper case


#include<stdio.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]>=97&&str[i]<=122)
            str[i]=str[i]-32;
  }
  printf("\nThe string in lowercase 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.

6 comments:

Unknown said...

include the header file "string.h"
then the function"strlen" will work

Anonymous said...

can someone convert these codes into C++ language?

Anonymous said...

u r absolutely ri8...

Anonymous said...

Yeah, even by using "toupper" function we can convert it directly to uppercase... but this program has ability to works without string library..!

Anonymous said...

#include
#include

void main(void)
{
char x[50];
int i=0;
puts("Enter the String: ");
gets(x);
while(x[i]!='\0')
{
x[i] = toupper (x[i]);
i++;
}
printf("\nYour String in Uppercase %s\n", x);

system("PAUSE");
return 0;
}

Unknown said...

How we can write a program by using strupr??