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.

36 comments:

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

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

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

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

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

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

      Delete
  6. scanf statement does not contain &

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

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

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

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

    ReplyDelete
  11. 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;
    }

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

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

    ReplyDelete
  14. create a function to change the case of alphebet

    ReplyDelete
  15. create a function to find factorial of anumber

    ReplyDelete
  16. create a function to the area of a triangle

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

    ReplyDelete
  18. 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);
    }

    ReplyDelete
  19. 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 :)

    ReplyDelete
  20. thanks boss i want this program only it works perfectly

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

    ReplyDelete
    Replies
    1. Morning

      Delete
    2. why morning..?plz explain

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

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

      Delete
  22. 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

    ReplyDelete
  23. #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();
    }

    ReplyDelete
  24. 1st character in to upper case

    ReplyDelete
  25. 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

    ReplyDelete
  26. 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));
    }
    }
    }

    ReplyDelete
  27. 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).

    ReplyDelete
  28. simply use build in function toupper of ctype library;

    ReplyDelete