isdigit ç à è

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

isdigit ç à è

 
0
  #1
Nov 19th, 2008
I have absolutely no clue why the following code works except for the following three characters: ç, à and è. It should rule out all non-digit characters from being written into an edit control. Because it let's those three pass trough I am forced to turn this:
  1. if(!isdigit(editControl_Content[2]))

into this:
  1. if(editControl_Content[2] == 'è' | editControl_Content[2] == 'ç' | editControl_Content[2] == 'à' | !isdigit(editControl_Content[2]))

This is the complete code:
  1. char editControl_Content[2];
  2. GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), &editControl_Content[2], 2);
  3.  
  4. if(editControl_Content[2] == 'è' | editControl_Content[2] == 'ç' | editControl_Content[2] == 'à' | !isdigit(editControl_Content[2])) {
  5. SetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), NULL);
  6. }
  7. else if(lockOn == false) {
  8. SetFocus(GetDlgItem(hwnd, LOWORD(wParam)+1));
  9. }

Any help would be very well appreciated.
Thank you.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 947
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is online now Online
Posting Shark

Re: isdigit ç à è

 
0
  #2
Nov 19th, 2008
First you're using the wrong "OR". For comparisons it's "||", not the bit-operation 'or' "|".
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: isdigit ç à è

 
0
  #3
Nov 19th, 2008
Originally Posted by MosaicFuneral View Post
First you're using the wrong "OR". For comparisons it's "||", not the bit-operation 'or' "|".
My bad, it's 0.20 here, typed it wrong...

EDIT: is this because è, ç, à are Extended ASCII?
Last edited by brechtjah; Nov 19th, 2008 at 7:26 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: isdigit ç à è

 
0
  #4
Nov 19th, 2008
'ç' has a decimal value of -25, and isdigit() only works with positive signed integer values.
Last edited by Ancient Dragon; Nov 19th, 2008 at 11:24 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 947
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is online now Online
Posting Shark

Re: isdigit ç à è

 
0
  #5
Nov 20th, 2008
See if this works:
  1. int isNum(char c)
  2. {
  3. if((int)c > 47 && (int)c < 58) { return(true); }
  4. return(false);
  5. }
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: isdigit ç à è

 
0
  #6
Nov 20th, 2008
You are not getting the window text properly, it should be

  1. char editControl_Content[2];
  2. // the following gets one char into editControl_Content[0] and sets
  3. // editControl_Content[1] to '\0'
  4. int charCount = GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), editControl_Content, 2);
  5. if(charCount > 0)
  6. {
  7. // got a char ...
  8. }

And further on, when you use isdigit(), be sure to use the valid index (0) i.e.
  1. if(isdigit(editControl_Content[0]))
  2. ...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: isdigit ç à è

 
0
  #7
Nov 20th, 2008
Some notes about isdigit and non-ascii characters:

The isdigit is a C library function (the C library is a part of C++ library) so let's open the C language standard:
The header <ctype.h> declares several functions useful for classifying and mapping
characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.
So isdigit domain is 0..255 + EOF macros (usually -1). It's well known that char type may be signed or unsigned. If it's signed, all non-ascii char values implicitly converted to negative integers (formally bad values for all isXXX family).
Fortunately it's so simple to cope with the problem in platform-independent manner, for example:
  1. if (isdigit(c&0xFF)) // 1st method
  2. if ((unsigned char)c) // 2nd method
  3. // C++ style radical method #3:
  4. inline bool isDigit(char c) { return c >= '0' && c <= '9'; }
The 3rd method gets the fastest code with a good compiler.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: isdigit ç à è

 
0
  #8
Nov 20th, 2008
Your second method is broken -- you forgot isdigit. Your third method is not radical.

Negative values will fail when a lookup table is used to implement the function -- they point in memory outside the lookup table.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: isdigit ç à è

 
0
  #9
Nov 20th, 2008
Originally Posted by Rashakil Fol View Post
Your second method is broken -- you forgot isdigit. Your third method is not radical.

Negative values will fail when a lookup table is used to implement the function -- they point in memory outside the lookup table.
#2 Yes, it's annoying misprint
#3 Radical means that it's absolutely implementation-independent method with a very fast instructions generated.
The last remark is a truism.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: isdigit ç à è

 
0
  #10
Nov 20th, 2008
Originally Posted by mitrmkar View Post
You are not getting the window text properly, it should be

  1. char editControl_Content[2];
  2. // the following gets one char into editControl_Content[0] and sets
  3. // editControl_Content[1] to '\0'
  4. int charCount = GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), editControl_Content, 2);
  5. if(charCount > 0)
  6. {
  7. // got a char ...
  8. }

And further on, when you use isdigit(), be sure to use the valid index (0) i.e.
  1. if(isdigit(editControl_Content[0]))
  2. ...

That doesn't seem right because when I try this:
  1. char editControl_Content[2];
  2. GetDlgItemText(hwnd, LOWORD(wParam), &editControl_Content[2], 2);
  3.  
  4. aString<< editControl_Content[2];
  5. MessageBox(hwnd, aString.str().c_str(), "title", MB_OK);

if I change aString<< editControl_Content[2]; to aString<< editControl_Content[0]; like you're saying I get jibberish, so I put jibberish as argument to isdigit().
Unless I'm mistaken, editControl_Content[2] is a valid argument for isdigit().

Thank
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC