•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 374,185 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 253 | Replies: 5
![]() |
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I am writing a function which will check if the letter is in upper case , if so it returns true otherwise false.
Following is the code, I have written, but what is wrong?
#include<iostream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int isUpperCase ( char );
int main()
{
int i;
char c;
cout<<"Enter a charactor : ";
cin>>c;
i = int ( c );
isUpperCase ( i );
return 0;
}
int isUpperCase ( i )
{
if ( i > 65 && i < 90 )
return 1;
else
return 0;
}
please comment.
Following is the code, I have written, but what is wrong?
#include<iostream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int isUpperCase ( char );
int main()
{
int i;
char c;
cout<<"Enter a charactor : ";
cin>>c;
i = int ( c );
isUpperCase ( i );
return 0;
}
int isUpperCase ( i )
{
if ( i > 65 && i < 90 )
return 1;
else
return 0;
}
please comment.
•
•
Join Date: Aug 2006
Location: Noida, India
Posts: 151
Reputation:
Rep Power: 2
Solved Threads: 16
How about...
cplusplus Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class Foo { public: bool isUpperCase( char t ) { string crap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int size = crap.length(); // check if the same return true //otherwise return false }; int main() { Foo test; cout << test.isUpperCase('a') << endl; cout << test.isUpperCase('A'); cin.get(); }
Last edited by iamthwee : May 9th, 2008 at 5:25 am.
Member of: F-ugly code club
Join today don't delay!
Join today don't delay!
•
•
Join Date: Nov 2007
Posts: 770
Reputation:
Rep Power: 4
Solved Threads: 154
You are excluding the lower and upper bounds, so you could change to
if ( i >= 65 && i <= 90 )
or
if ( i > 64 && i < 91 )
The standard libraries provide functions for checking characters, see e.g. here
http://www.cplusplus.com/reference/clibrary/cctype/
•
•
Join Date: Apr 2008
Posts: 275
Reputation:
Rep Power: 1
Solved Threads: 37
hi,
you can also mask bit on position# 6, which is 0 if char is upper case and 1 if char is lower case, e.g. 'A' = 0x41 = 0100 0001 (binary), 'a' = 0x61 = 0110 0001 (binary).
krs,
tesu
you can also mask bit on position# 6, which is 0 if char is upper case and 1 if char is lower case, e.g. 'A' = 0x41 = 0100 0001 (binary), 'a' = 0x61 = 0110 0001 (binary).
c++ Syntax (Toggle Plain Text)
bool isUpperCase (char c) {return !(c&0x20);} . . . char c='z'; cout<<c<<(isUpperCase(c)?" is upper ":" is lower ")<<"char"; // z is lower char
krs,
tesu
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Insertion Sort Problem (C++)
- Ask Function problem?thanks (C)
- Abstract Class member function problem (C++)
- Function Problem. Please help (PHP)
- using OCI to call a ORACLE stored function (C++)
- static function problem (C++)
- AnsiString Template Data Return Problem Builder 6 (C++)
Other Threads in the C++ Forum
- Previous Thread: cash register help..!!
- Next Thread: need help with program



Linear Mode