Assertion Error

i am using below code to check whether alpha numeric chara.
this code breaks at the second line ie at if condition
and shows assertion error

for ( int pos = 0; pos < sInputWord.length(); ++pos )
{
if (isalnum(sInputWord.at(pos)))//if (isalpha(sInputWord.at(pos)))
// if (isalnum(sInputWord.at(pos))) original line
{
iEngFlag++;
}
}

Please tell me how to fix this

You don't need to worry about if they enter a letter or a number when writing simple programs, if they input garbage, it outputs garbage.

But if you really want to do so, you can check if the letters are in the number or letter range by doing a cast to int.

http://dochome.programbl.com/dochome/sites/default/files/image168.png
Maybe this problem:

https://msdn.microsoft.com/en-us/library/k84c0490%28v=VS.71%29.aspx

MSDN wrote:
When used with a debug CRT library, isalnum will display a CRT assert if passed a parameter that isn't EOF or in the range of 0 through 0xFF. When used with a debug CRT library, isalnum will use the parameter as an index into an array, with undefined results if the parameter isn't EOF or in the range of 0 through 0xFF.
Just to add to coder777 explanation:
If on your machine char is signed (which it most likely is), and you will use characters from uper ASCII plane (codes 128 - 255), for example if you want neat table borders or are using some non-english codepage, then integral values of such characters will be negative and not in range 00-FF as MS implementation requires.
Topic archived. No new replies allowed.