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?
Printable View
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?
What type of application are you preparing: console or UI. for what system (Windows, Unix, ...)?
This function might be handy http://msdn.microsoft.com/en-us/library/fcc4ksh8.aspx
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
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
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));
Is your build UNICODE or MBCS?
If UNICODE - try using iswdigit instead.
i have tries iswdigit() and also include <ctype.h> and <wchar.h> but error occur at compilation time "Unable to open file wchar.h
UNICode n if don't include it then error occur "iswdigit should have prototype"
What compiler do you use?
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"