c++ - Access violation reading location 0x00000006 -
i have following code finds strings contain no alphabets. cases mynumber123 shall not recognized , numberfinder() should return false , case 123 shall recognized , numberfinder() shall return true begin index of number.
the constructor:
caddressparser::caddressparser(string filename) //constructor { m_filename=filename; int length=getlength(m_filename.c_str()); m_text =filereader(m_filename.c_str()); m_length=length; }
which initializes string m_text
contains contents of text file
somewhere along implementation come across following code:
for (i;i<m_length;i++) { bool uppercasebeforenofound=false; if(this->numberfinder (i).second) { //do calculations. } }
the numberfinder function implemented follows:
pair <int,bool> caddressparser::numberfinder(int counter) { bool nofound=isdigit(m_text[counter]); //number found? -> true if(nofound) { int end=housenodigits(counter); if(((counter-1)>=0) && ((counter +end-1) <m_length)) { if((!(isalpha(m_text[counter-1]))) && (!isalpha(m_text[counter+end-1]))) { return make_pair(counter,nofound); //return index if true } } } else return make_pair(0,nofound); }
now problem text file containing following text "he23 market street london q12 h13". error mentioned in headline , debugger takes me line in contains :
if(this->numberfinder (i).second)
i can't figure out why happening. please me figure out.
access violation error due null reference. 1 of function calling trying access null pointer. make sure isdigit function returns true or false, m_text points exiting memory location. if not need allocate memory. should check if filename null.
Comments
Post a Comment