Results 1 to 4 of 4

Thread: How to Convert uppercase characters into lowercase characters in C++

  1. #1
    Join Date
    Oct 2008
    Posts
    20

    How to Convert uppercase characters into lowercase characters in C++

    Hello friends

    I just started learning C++ i want to know How to Convert UPPERCASE CHARACTERS Into lowercase characters in C++ ?

    Can anyone help me


    Thanks

  2. #2
    Join Date
    May 2008
    Posts
    37

    Re: How to Convert uppercase characters into lowercase characters in C++

    // Following example, converts UPPERCASE characters in a string to lower case string

    # include <iostream.h> // Header file for input output streams

    # include <string.h> // Header file for string related functions such as strlen()



    // Here is the function declaration "StrToLwr" for converting upper case characters in a string to lower case characters. The function takes two arguments. Both are char type pointers. First one is the actual string passed to it for conversion. The second argument will send the result back to the calling program. The function will convert only UPPERCASE CHARACTERS to lowercase characters. Every other character will remain as it is

    void StrToLwr(char* mainstring, char *output)

    {

    int Len = strlen(mainstring); // Len will contain the length of the passed string.

    for(int i = 0; i < Len; i++) // Now we will move from the 0th character in the string till its length and we will check if its a UPPERCASE character and then change it to lowercase characters.

    {

    if( (int)mainstring[i] < 65) // If the ASCII code of the character i.e. integer value of the character is less than 65, then copy the character as it is into the result string. It means that the character is not in the range of upper case characters

    output[i] = mainstring[i];

    if( (int)mainstring[i] >= 65 && (int)mainstring[i] <= 90) // If the ASCII code of the character i.e. integer value of the character is between 65 and 90, then its a UPPERCASE CHARACTER and let's convert it into the lowercase. By adding 32 in the ASCII number of the character, the character will be converted to lowercase. Such as, the ASCII code of UPPERCASE A is 65 and the ASCII code of lowercase a is 97. If we add 32 to UPPERCASE A, its ASCII code will become 97 and the character is changed from UPPERCASE to lowercase

    output[i] = (char)mainstring[i] + 32;

    if( (int)mainstring[i] >= 97 && (int)mainstring[i] <= 122) // If the ASCII code of the character i.e. integer value of the character is between 92 and 122, then copy the character as it is into the result string. It means that the character is not in the range of upper case characters. This is the range for lowercase characters

    output[i] = (char)mainstring[i];

    if( (int)mainstring[i] > 122) // If the ASCII code of the character i.e. integer value of the character is greater than 122, then copy the character as it is into the result string. It means that the character is not in the range of upper case characters. This range contains the graphical ASCII characters.

    output[i] = mainstring[i];

    }

    output[i] = '\0'; // Null terminating the string to show the end of the string

    }



    // Here is the main program which will be using the C_File function

    void main()

    {

    char arr1[21]="PRAsHANT"; // String to be converted

    char arr2[21]; // Result will be stored here

    StrToLwr(arr1,arr2); // Calling the function

    cout<<arr2; // Display the result

    } // End of main function

  3. #3
    Join Date
    Oct 2008
    Posts
    54

    Re: How to Convert uppercase characters into lowercase characters in C++

    Here is the Program that will convert lower case letters to upper case

    Code:
    #include<iostream.h>
    #include<conio.h>
    
    void main()
    {
    
    clrscr();
    char ch;
     	cout<<"enter a character";
     	cin>>ch;
    {
    if((ch>=65)&&(ch<=122))
    {
    if((ch>=97)&&(ch<=122))
    ch=ch-32;
    	
    	cout<<"The upper case character corresponding is"<<endl;}
    
    
    {if((ch>=65)&&(ch<=90))
    ch=ch+32;
    
    	 cout<<"The lower case character corresponding is"<<endl;}
    	
    
    	 cout<<"the character is not a letter"<<endl;
    }
    
    	 getch();
    
    }

  4. #4
    Join Date
    Oct 2008
    Posts
    1

    Program to convert all characters in a string to lowercase

    #include<iostream.h>
    void main()
    {
    char a[50];
    cin.getline(a,50);
    for(int i=0;a[i]!='\0';i++)
    {
    if(a[i]>=65&&a[i]<=90)
    a[i]+=32;
    }
    cout<<endl<<a;
    }

Similar Threads

  1. Replies: 3
    Last Post: 14-01-2014, 09:44 AM
  2. Replies: 5
    Last Post: 23-12-2010, 07:12 PM
  3. Convert text to uppercase/lowercase using Macros
    By Anas in forum Windows Software
    Replies: 3
    Last Post: 02-05-2009, 02:23 PM
  4. How to Convert uppercase to lowercase in excel?
    By Imtiyaz in forum Windows Software
    Replies: 3
    Last Post: 29-04-2009, 11:59 PM
  5. Convert lowercase to uppercase
    By ERWAN in forum MS Office Support
    Replies: 1
    Last Post: 09-10-2008, 10:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,461,689.09098 seconds with 17 queries