How to check if character is decimal digit

1 01 2009

Some times we have a string value and we need to ensure that all the characters belong to them are decimal digits(0 – 9). Its very easy to tackle this by using the function isdigit.

 int isdigit ( int c )

c – character to be checked

Please check the code snippet below.

void CheckDigit()
   CString str = "123s4";
   int nIndex  = 0;
   for( nIndex = 0; nIndex < str.GetLength(); nIndex++ )
         printf("Non-decimal digit: [%c] found in the string.",str[nIndex]);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: