Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-10-2008
Member
 
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
Reply With Quote
  #2  
Old 25-10-2008
Member
 
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
Reply With Quote
  #3  
Old 25-10-2008
Member
 
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();

}
Reply With Quote
  #4  
Old 25-10-2008
Member
 
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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Convert uppercase characters into lowercase characters in C++"
Thread Thread Starter Forum Replies Last Post
How to convert Traditional Chinese characters to Simplified Chinese characters in Microsoft Excel 2007 Zebadiah MS Office Support 3 14-01-2014 09:44 AM
Special Characters in SMS turn them shorter (70 characters instead of 160 characters) Xymaya Portable Devices 5 23-12-2010 07:12 PM
Convert text to uppercase/lowercase using Macros Anas Windows Software 3 02-05-2009 02:23 PM
How to Convert uppercase to lowercase in excel? Imtiyaz Windows Software 3 29-04-2009 11:59 PM
Convert lowercase to uppercase ERWAN MS Office Support 1 09-10-2008 10:16 AM


All times are GMT +5.5. The time now is 11:53 PM.