fgets throwing unhandled exception while parsing stl
Posted
by
user3478400
on Stack Overflow
See other posts from Stack Overflow
or by user3478400
Published on 2014-05-29T03:21:14Z
Indexed on
2014/05/29
3:25 UTC
Read the original article
Hit count: 145
I am new to c++, I am trying to parse a stl file which is of about 64MB and has about ~18K lines in it. The code works fine for first few 100 lines but then fgets throws following exception:
"Unhandled exception at 0x77B0BAC5 (ntdll.dll) in STLparser.exe: 0xC0000024: There is a mismatch between the type of object required by the requested operation and the type of object that is specified in the request."
I have checked manually the line for which fgets throws exception, there is nothing out of ordinary there. I am out of options for now. Any help to fix this issue will be greatly appreciated.
================CODE==========================
#include<fstream>
#include<iostream>
#include"ParseString.h"
#include"Vectors.h"
using namespace std;
int main(void)
{
//Define variables
FILE *file;
char *line = new char;
parsestring oneline;
int n_Vols = 0, n_Elms = 0, n_nods = -1, E = 0;
Nod *nodes = new Nod();
Nod dummy;
Elm *elements = new Elm();
int mycounter = 0;
//Open file
fopen_s(&file, "sample.stl", "r");
while (fgets(line, 1024, file) != NULL) //**********Getting Error Here*************
{
// populate required data
}
fclose(file);
printf("%d,%d,%d", n_Vols, n_Elms, n_nods);
getchar();
return 0;
}
===================When broken, execution resumes at this function (not my function, something internal)
void __cdecl _unlock ( int locknum ) { /* * leave the critical section. */ LeaveCriticalSection( _locktable[locknum].lock ); }
© Stack Overflow or respective owner