That debug assertion error originates from the call to std::isalpha/isdigit
when you pass it an argument with a value > 255, which is the maximum value the type char
(which you should probably be using instead of int
here) can hold. I can't tell you the exact origin though as you don't provide the source file, but you should be able to figure it out yourself quite easily: run the program under the debugger, it will break at the assert. Move up in the call stack and inspect the values of your variables, that should give you a clue.
a couple of tips:
- you're using c++ here, no need for using raw char arrays. Use std::string instead.
- don't put using namepsace std; in header files: everything incuding that file will import the entire std namespace
- if you include in a header, you don't have t include it again in the source file
- learn to use the debugger, it's an invaluable tool and will aid you in learning why something is wrong
manpreet
Best Answer
2 years ago
I am working on writing a compiler for a school project, and this assignment calls for me to print the tokens of a text file to the console window. I want to make it clear I do not want my homework done for me.
I have been working with this stupid function that iterates through the file, and concatenates a char or a c-string value (my tutor was vague on this part of his instructions...) to a string variable named "token." I can work through the first line of the file fine, which is "main()", but when I try and access the next line I get 1 of two errors. The first is a string subscript out of range error, though I think this was because I was trying to access part of a string array that didn't exist. The most prevalent error I am getting is a debug assertion error:
I have included my function and its associated header file. Nothing is going on in main except a function call. If at all possible, could you see what I am failing to see. I realize that my code structure is poor, I won't lie (I am in school after all). So, any comments, criticism, and suggestions are very welcome. And always,thank you for any and all time.
.CPP File (As it is now)
.h file