title: What can cause a Debug Assertion Error. Specifically, in my code
body: <p>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 <strong>do not</strong> want my homework done for me. </p>
  
  <p>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 <strong>prevalent</strong> error I am getting is a debug assertion error:</p>
  
  <blockquote>
    <p>Debug Assertion Failed  Final.exe
    File:f:\dd\vctools\crt_bld\self_x86\crt\src\isctype.c Expression:
    (unsigned)(c+1) &lt;= 256</p>
  </blockquote>
  
  <p>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.  </p>
  
  <p>.CPP File (As it is now) </p>
  
  <pre><code>    #include &lt;iostream&gt; 
      #include &lt;string&gt;
  
      using namespace std; 
  
      void tokenWork::openFile()
      {
          fileName = "test.txt"; 
  
          source.open(fileName);
  
          if(!source.is_open())
          {
         cout &lt;&lt; "Cannot find file " &lt;&lt; endl; 
          }
      }
  
      void tokenWork::traveseLine()
      {
  
      pos = 0; 
      while (!source.eof())
      {  
            getline(source,myLine); 
            int length = myLine.length(); 
            letters = new char[length];
            myLine.copy(letters,length); 
  
            c = letters[pos]; 
  
            if (isalpha(c))
               token = token + myLine[pos]; 
            else if (isdigit(c))
               token = token + letters; 
            else 
            {
               cout &lt;&lt; token &lt;&lt; endl; 
               token = ""; 
            }
  
            if (c == '{' || c == '}' || c == '+' || c == '=' || myLine[pos] == '(' || c == ')' || c == ';')
                  cout &lt;&lt; myLine[pos] &lt;&lt; endl;  
            c = letters[pos++]; 
      }
  }
  </code></pre>
  
  <p>.h file</p>
  
  <pre><code>    #ifndef H_LEX
      #define H_LEX
  
      #include &lt;string&gt; 
      #include &lt;iostream&gt; 
      #include &lt;fstream&gt; 
  
      using namespace std; 
  
      class tokenWork
      {
      public: 
      std::string fileName; 
      std::string myLine; 
      std::string token; 
  
      int pos; 
      int length; 
      int c;
  
      char *letters; 
  
      ifstream source; 
  
      void openFile(); 
      void traveseLine(); 
      void closeFile(); 
  
  };
  
      #endif 
  </code></pre>