-
February 22nd, 2012, 02:40 AM
#1
Only number can be accepted
Helo
i am preparing project,in which i want to perform operation like user can only enter number 0 to 9 and can't enter alphabet or special symbol...for i have try many code but can't perform.... any one help me?
-
February 22nd, 2012, 03:10 AM
#2
Re: Only number can be accepted
What type of application are you preparing: console or UI. for what system (Windows, Unix, ...)?
Victor Nijegorodov
-
February 22nd, 2012, 10:50 AM
#3
Re: Only number can be accepted
-
February 23rd, 2012, 12:00 AM
#4
Re: Only number can be accepted
I am using windows 7 n i have switch case in which i want to do this only accept digit if user enter alphabet then message will be print
-
February 23rd, 2012, 01:54 AM
#5
Re: Only number can be accepted
Then check every character to be between 0 and 9, if not - don't accept this character.
If your app is a GUI one then the best way is to handle WM_CHAR message
Victor Nijegorodov
-
February 23rd, 2012, 02:29 AM
#6
Re: Only number can be accepted
i m not working in GUI. isdigit() do not work.
int ch;
do
{
cout<<enter choice;
cout<<1
cout<<2
cout<<3
cin>> ch
int c=isdigit(ch)
if(c!=0)
{
switch(ch)
{
case 1:cout<<"one";break
case 2:cout<<"two";break
case 3:exit;
}
else
cout<<"Enter only digit";
}
}while(!(ch==3));
-
February 23rd, 2012, 03:50 AM
#7
Re: Only number can be accepted
Is your build UNICODE or MBCS?
If UNICODE - try using iswdigit instead.
Victor Nijegorodov
-
February 23rd, 2012, 04:50 AM
#8
Re: Only number can be accepted
i have tries iswdigit() and also include <ctype.h> and <wchar.h> but error occur at compilation time "Unable to open file wchar.h
-
February 23rd, 2012, 05:06 AM
#9
Re: Only number can be accepted
Originally Posted by CSharpque
i have tries iswdigit() and also include <ctype.h> and <wchar.h> but error occur at compilation time "Unable to open file wchar.h
Then don't include them!
And, BTW, you didn't answer yet:
UNICODE or MBCS?
Victor Nijegorodov
-
February 23rd, 2012, 05:30 AM
#10
Re: Only number can be accepted
UNICode n if don't include it then error occur "iswdigit should have prototype"
-
February 23rd, 2012, 05:35 AM
#11
Re: Only number can be accepted
What compiler do you use?
-
February 23rd, 2012, 05:42 AM
#12
Re: Only number can be accepted
Originally Posted by CSharpque
i have tries iswdigit() and also include <ctype.h> and <wchar.h> but error occur at compilation time "Unable to open file wchar.h
Could you show your actual code (please, use Code tags!) with and exact error message?
Victor Nijegorodov
-
February 24th, 2012, 12:07 AM
#13
Re: Only number can be accepted
if i include <ctype.h> it will give error "Function iswdigit() should have prototype" so i delete <ctype.h> and include <wchar.h> file but it also gives 2 error "Unable to open include file 'WCHAR.H'" and second error "Function iswdigit() should have prototype"
Last edited by CSharpque; February 24th, 2012 at 12:12 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|