| | |
isdigit ç à è
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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:
into this:
This is the complete code:
Any help would be very well appreciated.
Thank you.
cpp Syntax (Toggle Plain Text)
if(!isdigit(editControl_Content[2]))
into this:
cpp Syntax (Toggle Plain Text)
if(editControl_Content[2] == 'è' | editControl_Content[2] == 'ç' | editControl_Content[2] == 'à' | !isdigit(editControl_Content[2]))
This is the complete code:
cpp Syntax (Toggle Plain Text)
char editControl_Content[2]; GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), &editControl_Content[2], 2); if(editControl_Content[2] == 'è' | editControl_Content[2] == 'ç' | editControl_Content[2] == 'à' | !isdigit(editControl_Content[2])) { SetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), NULL); } else if(lockOn == false) { SetFocus(GetDlgItem(hwnd, LOWORD(wParam)+1)); }
Any help would be very well appreciated.
Thank you.
See if this works:
C++ Syntax (Toggle Plain Text)
int isNum(char c) { if((int)c > 47 && (int)c < 58) { return(true); } return(false); }
"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
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
You are not getting the window text properly, it should be
And further on, when you use isdigit(), be sure to use the valid index (0) i.e.
cpp Syntax (Toggle Plain Text)
char editControl_Content[2]; // the following gets one char into editControl_Content[0] and sets // editControl_Content[1] to '\0' int charCount = GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), editControl_Content, 2); if(charCount > 0) { // got a char ... }
And further on, when you use isdigit(), be sure to use the valid index (0) i.e.
cpp Syntax (Toggle Plain Text)
if(isdigit(editControl_Content[0])) ...
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:
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:
The 3rd method gets the fastest code with a good compiler.
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.
Fortunately it's so simple to cope with the problem in platform-independent manner, for example:
C++ Syntax (Toggle Plain Text)
if (isdigit(c&0xFF)) // 1st method if ((unsigned char)c) // 2nd method // C++ style radical method #3: inline bool isDigit(char c) { return c >= '0' && c <= '9'; }
•
•
•
•
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.

#3 Radical means that it's absolutely implementation-independent method with a very fast instructions generated.
The last remark is a truism.
•
•
•
•
You are not getting the window text properly, it should be
cpp Syntax (Toggle Plain Text)
char editControl_Content[2]; // the following gets one char into editControl_Content[0] and sets // editControl_Content[1] to '\0' int charCount = GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), editControl_Content, 2); if(charCount > 0) { // got a char ... }
And further on, when you use isdigit(), be sure to use the valid index (0) i.e.
cpp Syntax (Toggle Plain Text)
if(isdigit(editControl_Content[0])) ...
That doesn't seem right because when I try this:
cpp Syntax (Toggle Plain Text)
char editControl_Content[2]; GetDlgItemText(hwnd, LOWORD(wParam), &editControl_Content[2], 2); aString<< editControl_Content[2]; 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
![]() |
Similar Threads
- WinHugs - using isDigit (Legacy and Other Languages)
- infinite loop... (C++)
- Keyboard Error Handling (C++)
- cin.peek (C++)
- Homework Help/Feedback (C++)
- Need Help With Error Checking User Input (C)
- 10, 20, 0 (C)
Other Threads in the C++ Forum
- Previous Thread: Quicksort strings?
- Next Thread: Need homework help
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






