character validation

Hey all I'm struggling with my project to extract occurrences of a word from a text file. The semantics of opening/using the file are giving me massive headaches, but first off I'd really like just to be able check a given letter for being part of a word.

It seems like an easy task in C, just using isAlpha(), but the same thing doesn't seem to work in C++. What's the #include file for a similar function?

My code is:

bool isNotWhitespace(char c){
return ((isaplha(c) != 0) || c == "-" || c == "'");

but that gives me a whole host of errors, mostly about conversion from char* to int. The documentation didn't seem to mention it, and it's not even a char*?!!

any help appreciated
Use single quotes ( ' ) to refer to the value of a single character. E.g. 'A'==65
Use double quotes ( " ) to refer to a pointer to static char array. E.g. sizeof("A")==sizeof(char *)

By the way, the only whitespace characters in ASCII are 0x09, 0x0A, 0x0B, 0x0C, 0x0D, and 0x20. If we include ISO-8859-1, the list also includes 0x85 and 0xA0.
Last edited on
hey thats awesome!! its good finding these little tricks.

However in the spec I've got ' counts as a letter so I need to check for that. However when I write that, it's just three apostrophes (''') so makes the rest of my code into a quote?
'\'' - apostrophe
'\n' - newline or line feed (10)
'\r' - carriage return (13)
'\t' - tab (9)
'\\' - backslash
'\0' - nul (zero)
'\xFF' == 0xFF
'\xFFFF' == 0xFFFF (this may need an L in front, e.g. L'\xFFFF')
Last edited on
Topic archived. No new replies allowed.