|
Guest
Posts: n/a
|
In article < .com>,
"electrixnow" <info...@charter.net> wrote:
> I have changed the code and it still blows up at 182 lines
> I found that if I comment out the two string lines noted that it runs
> to 19000 + lines. suggested I was pushing it with
> the array size but it works fine. I the array is full with no error
> after the
> while statement.
>
> Any clue?
>
> and I am mixing C and C++ because have just started using C++
> with VC++ Express, it was free, and I have not found a good online
> C++ reference. I use to program in C type shell languages in the 80's.
> So I need a good online or electronic VC++ reference library. or
> hardback
> would work, any suggestions are welcome. Thanks for the help thus far.
<http://www.sgi.com/tech/stl/>
>
> #include <fstream>
> #include <iostream>
> #include <string>
>
> #define MOVEX_QUERY "C:\\DWG_DATA\\DOCUMENTS_movex.csv" //
>
> int main(){
> char * document;
> char * edition;
> char * str1;
> char * next_token1;
> int lines=0;
>
> using namespace std;
>
> ifstream inf(MOVEX_QUERY);
>
> if (inf)
> {
> char namn[20000][30];
> while (lines < 20000 && (inf.getline(namn[lines], 30)) !=
> NULL)++lines;
> for (int i = 0; i < lines; ++i){
> str1 = namn[i];
> cout << str1 << '\n';
>
> document = strtok_s( str1, " ,\t\n", &next_token1);
> edition = strtok_s( NULL, " ,\t\n", &next_token1);
I think the reason it crashes is because at line 182 in the file,
'document' is NULL. To prove it do this:
string doc;
string edi;
if ( document && edition ) {
doc = document;
edi = edition;
}
else { cout << "Would have crashed!\n"; }
> // string doc(document); // if these two lines are removed
> // string edi(edition); // it will run to 19000 + lines
> 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;
> }
>
> Here is a sample of the data being input.
>
> 00-00008RA,0004,,,,,,
> 00-00009RA,0003,,,,,,
> 00-00010RA,0003,,,,,,
> 00-00019RA,0005,,,,,,
> 00-00021RA,0016,,,,,,
> 00-00036RA,0016,,,,,,
> 00-00041RA,0005,,,,,,
> 00-00042RA,0009,,,,,,
> 00-00043RA,0003,,,,,,
> 00-00045RA,0008,,,,,,
> 00-00047RA,0018,,,,,,
> 00-00051RA,0018,,,,,,
> 00-00052RA,0029,,,,,,
> 00-00054RA,0028,,,,,,
> 00-00055RA,0023,,,,,,
> 00-00056RA,0006,,,,,,
> 00-00057RA,0008,,,,,,
> 00-00058RA,0005,,,,,,
> 00-00059RA,0005,,,,,,
> 00-00076RA,0006,,,,,,
> 00-00085RA,0025,,,,,,
> 00-00086RA,0025,,,,,,
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
|
|