c++ - Unhandled exception at 0x00B67361 -


i trying read .dat files 2d array, tried read same files 1d arrays such each line each array. however, code below 2d array message box pop stating " unhandled exception @ 0x00b67361 in consoleapplication11.exe: 0xc0000005: access violation reading location 0x00000000." , not finish execution". what's reason behind unhandled exception? use vs 2012 express edition.

do {         char * s = find_data.cfilename;          ifstream fin;         fin.open(s); // open file         if (!fin.good())              return 1; // exit if file not found          // read each line of file         while (!fin.eof())         {             // read entire line memory             char buf[max_chars_per_line];             int n = 0;             int s = 0;             int m = 0;              // array store memory addresses of tokens in buf             const char* token[max_tokens_per_line][max_tokens_per_line] = {}; // initialize 0             (m = 1; m < max_tokens_per_line; m++)             {                 fin.getline(buf, max_chars_per_line);                  // parse line blank-delimited tokens                 // for-loop index                 //char* next_token[max_tokens_per_line] = {}; // initialize 0                 char *next_token;                 // parse line                 token[0][0] = strtok_s(buf, delimiter, &next_token); // first token                 //token[0] = strtok(buf, delimiter); // first token                 if (token[0][0]) // 0 if line blank                 {                     (n = 1; n < max_tokens_per_line; n++)                     {                         token[m][n] = strtok_s(0, delimiter, &next_token); // subsequent tokens                         //token[n] = strtok(0, delimiter); // subsequent tokens                         if (!token[m][n]) break; // no more tokens                     }                 }             }             // process (print) tokens             (int = 0; < n; i++) // n = #of tokens                 (int j = 0; j < m; j++)                 {                     cout << "token[" << << "," << j << "] = " << token[i][j] << endl;                     cout << endl;                  }         }         // code here     } while( findnextfile( h, & find_data ) );     findclose( h ); 

q: 0xc0000005: access violation reading location 0x00000000. what's reason behind unhandled exception?

a: you're reference null pointer in code :)

suggestion:

single-step through msvs debugger. pay careful attention every time strtok_s() returns "0" ... , make sure don't try access null pointer later. make sure you're processing 8-bit characters (who knows: compiler settings might giving 16-bit unicode). important: identify exact line that's causing crash, , work backward data line processing.

msvs has great debugger: should able find - , correct - problem in no time :)

good luck!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -