E
electrixnow
I have the following test code that opens and reads a file.
The file is over 19000 lines long. The file contains two fields
on each line: "text,text\n"
I have placed a test that for loops up to 182 and the program errors
out.
I placed the error message after the code:
I am using VC++ Express Edition
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#define MOVEX_QUERY "C:\\DWG_DATA\\DOCUMENTS_movex.csv"
int main(){
char * document;
char * edition;
char * str1;
char * next_token1;
int i=0;
using std::string;
using std::ifstream;
using std::cout;
ifstream inf(MOVEX_QUERY);
if (inf)
{
char namn[20000][30];
while ((inf.getline(namn, 30)) != NULL)++i;
for (int i = 0; i < 182; ++i){
str1 = namn;
cout << str1 << '\n';
document = strtok_s( str1, " ,\t\n", &next_token1);
edition = strtok_s( NULL, " ,\t\n", &next_token1);
std::string doc(document);
std::string edi(edition);
if ( edi == doc ) cout << "THIS WORKS" <<'\n';
printf( "%s\n", document );
printf( "%s\n", edition );
cout << i <<'\n';
}
}
else
{
cout << "Could not open file\n";
return 1;
}
cout << "PROCESSING COMPLETE\n";
return 0;
}
This is just test code, there are things that could be removed.
If I change the for loop to 182 or greater
I get a message as follows:
Unhandled Exception: System.AccessViolationException: Attempted to read
or write
protected memory. This is often an indication that other memory is
corrupt.
SByte* )
at main() in c:\documents and settings\grant\my documents\visual
studio 2005\
projects\documents\document1\document1\doc1.cpp:line 31
Press any key to continue . . .
Attempted to read or write protected memory
Please let me know what you think
Thanks
The file is over 19000 lines long. The file contains two fields
on each line: "text,text\n"
I have placed a test that for loops up to 182 and the program errors
out.
I placed the error message after the code:
I am using VC++ Express Edition
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#define MOVEX_QUERY "C:\\DWG_DATA\\DOCUMENTS_movex.csv"
int main(){
char * document;
char * edition;
char * str1;
char * next_token1;
int i=0;
using std::string;
using std::ifstream;
using std::cout;
ifstream inf(MOVEX_QUERY);
if (inf)
{
char namn[20000][30];
while ((inf.getline(namn, 30)) != NULL)++i;
for (int i = 0; i < 182; ++i){
str1 = namn;
cout << str1 << '\n';
document = strtok_s( str1, " ,\t\n", &next_token1);
edition = strtok_s( NULL, " ,\t\n", &next_token1);
std::string doc(document);
std::string edi(edition);
if ( edi == doc ) cout << "THIS WORKS" <<'\n';
printf( "%s\n", document );
printf( "%s\n", edition );
cout << i <<'\n';
}
}
else
{
cout << "Could not open file\n";
return 1;
}
cout << "PROCESSING COMPLETE\n";
return 0;
}
This is just test code, there are things that could be removed.
If I change the for loop to 182 or greater
I get a message as follows:
Unhandled Exception: System.AccessViolationException: Attempted to read
or write
protected memory. This is often an indication that other memory is
corrupt.
(basic_string<char\,std::char_traits<char>\,std::allocator<char> >* ,at std.basic_string said:.{ctor}
SByte* )
at main() in c:\documents and settings\grant\my documents\visual
studio 2005\
projects\documents\document1\document1\doc1.cpp:line 31
Press any key to continue . . .
Attempted to read or write protected memory
Please let me know what you think
Thanks