C++ program to pass a character as call by reference and apply character case conversion

#include <iostream>
using namespace std;
void CaseConversion(char *);
int main()
{
    char ch;
    cout<<"Enter a character: ";
    cin>>ch;
    cout<<"Before conversion: "<<ch<<endl;
    CaseConversion(&ch);
    cout<<"After conversion: "<<ch;
    return 0;
}
void CaseConversion(char *c)
{
    if(*c>=65 && *c<=90)
        *c=*c+32;
    else if(*c>=97 && *c<=122)
        *c=*c-32;
    else
        *c=*c;
}

No comments:

Post a Comment