title: String subscript out of range in line 1331 of xstring
body: <p>The second while loop is throwing an exception in xstring line 1441 on the second iteration, which it should not do. This is because on the first pass:</p>
  
  <pre><code>Testthis-&gt;NAME[n] = 'B'
  Testthis-&gt;NAME[n+1] = 'O'
  Testthis-&gt;NAME = "BOD MQL"
  </code></pre>
  
  <p>are all verified from the debug <code>cout</code> statements. I am stumped on this one.</p>
  
  <pre><code>struct Node * ProbableMatch(struct Node * Look_in, int MaxNodes, char Findthis[64]){
  system("cls");
  int i=0,proba=100,CurrentHigh=100;
  size_t pos1=1,n1=0,n2=0,pos2=1;
  //char s[64];
  struct Node * CurrentHighProb;
  struct Node * Testthis;
  CurrentHighProb=new(Node);
  Testthis=new(Node);
  Testthis=Look_in;
  //for(i=0;i==MaxNodes;i++)
  while(!Testthis || i!=ccounter)
  {
      gotoxy(0,0);
      int n=0;
      n1=sizeof(Look_in-&gt;NAME);
      n2=sizeof(Findthis);
      string str1;
      char str2[64];
      cout&lt;&lt;Testthis-&gt;NAME[n]&lt;&lt;endl&lt;&lt;Testthis-&gt;NAME&lt;&lt;endl;
      cout&lt;&lt;Testthis-&gt;NAME[n+1]&lt;&lt;endl;
  
      while(Testthis-&gt;NAME[n]!='\0'){  //mannually coverts the strings since I am having hell with the inbuilt functions
          cout&lt;&lt;Testthis-&gt;NAME[n];
          str1[n]=Testthis-&gt;NAME[n];
          if(Testthis-&gt;NAME[n+1]=='\0'){str1[n+1]='\0';}//makes NULL terminated strings
          n++;
      }//end of while
  
      //strcpy_s(cstr, str1.length());
      //strcpy_s(str1,sizeof(Look_in-&gt;NAME),Look_in-&gt;NAME);
      //strcpy_s(str2,sizeof(Findthis),Findthis);
      //char * cstr1 = new char[str1.length()+1];
      cout&lt;&lt;str1.compare(pos1,n1,Findthis,0,n2)&lt;&lt;" is the value of the string compare "&lt;&lt;endl;
      proba=str1.compare(pos1,n1,Findthis,0,n2);//compares Findthis to the varibles read from the database from string matches
  
      //DEBUG STUFF
      cout&lt;&lt;endl&lt;&lt;sizeof(Look_in-&gt;NAME)&lt;&lt;" sizeof(Look_in-&gt;NAME)"&lt;&lt;Look_in-&gt;NAME&lt;&lt;endl;
      cout&lt;&lt;sizeof(Findthis)&lt;&lt;" sizeof(Findthis)"&lt;&lt;Findthis&lt;&lt;endl;
      cout&lt;&lt;sizeof(str1)&lt;&lt;" "&lt;&lt;str1&lt;&lt;" string1   string2 "&lt;&lt;str2&lt;&lt;" "&lt;&lt;sizeof(str2)&lt;&lt;endl;
      //cout&lt;&lt;sizeof(str1)&lt;&lt;" reinterpret_cast&lt; char *&gt;(str1)"&lt;&lt;endl;
      system("PAUSE");
      cout&lt;&lt;"\n Probability of "&lt;&lt;Look_in-&gt;NAME&lt;&lt;" matching "&lt;&lt;Findthis&lt;&lt;" is "&lt;&lt;proba&lt;&lt;" ."&lt;&lt;endl;
      //ENDOFDEBUG FOR FUNCTION
      Testthis-&gt;prob=proba;
      if(proba==0)
      {
          cout&lt;&lt;"proba equals zero, match found returning "&lt;&lt;Look_in&lt;&lt;endl;
          //delete[] cstr1;
          return Testthis;  // returns the pointer of the varible that best matched the search
      }
      if(proba&lt;CurrentHigh){
          CurrentHigh=proba;
          CurrentHighProb=Testthis;
      }
      i++;
      Testthis=Testthis-&gt;next;
  }
  cout&lt;&lt;"Perfect match not found after "&lt;&lt;i&lt;&lt;" number of searches, returning this highest probable match "&lt;&lt;CurrentHighProb&lt;&lt;" "&lt;&lt;proba&lt;&lt;endl;
  
  system("PAUSE");
  //delete[] cstr1;
  return CurrentHighProb;
  }
  </code></pre>