Dave's Brain

Browse - Programming Tips - Is there a isalnum(), ispunct() etc that doesn't assert?

Date: 2016may30
Language: C++
Product: Visual C++

Q.  Is there a isalnum(), ispunct() etc that doesn't assert?

Debug Assertion failed! File: isctype.c Line: 56 Expression:(unsigned)(c+1) <= 256
A. Often this is cause by the programmer call isalnum() or other function with bad data (that's discussed on another page). But it could be that you just want to know if a certain character is a digit or not. Your program should not assert for asking that. So here are some functions that don't
#include <ctype.h> inline int noassert_isalpha(const int c) { return _isctype(c,_ALPHA); } inline int noassert_isupper(const int c) { return _isctype(c,_UPPER); } inline int noassert_islower(const int c) { return _isctype(c,_LOWER); } inline int noassert_isdigit(const int c) { return _isctype(c,_DIGIT); } inline int noassert_isxdigit(const int c) { return _isctype(c,_HEX); } inline int noassert_isspace(const int c) { return _isctype(c,_SPACE); } inline int noassert_ispunct(const int c) { return _isctype(c,_PUNCT); } inline int noassert_isalnum(const int c) { return _isctype(c,_ALPHA|_DIGIT); } inline int noassert_isprint(const int c) { return _isctype(c,_BLANK|_PUNCT|_ALPHA|_DIGIT); } inline int noassert_isgraph(const int c) { return _isctype(c,_PUNCT|_ALPHA|_DIGIT); } inline int noassert_iscntrl(const int c) { return _isctype(c,_CONTROL); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.