UIKit0 / bwapi

Automatically exported from code.google.com/p/bwapi
0 stars 0 forks source link

Trying read a file #484

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying read a file using this function, but crash =/

#include "QLearning.h"
#include <BWAPI.h>
#include <fstream>

char* QLearning::startByFile() {

    char* line;
    static std::ifstream myfile("bwapi-data\\logs\\QTable.txt");
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
        myfile.getline(line, 256);
    }
    myfile.close();
  }

      return line;
}

================

The call is:

      qLearning = new QLearning();
      Broodwar->printf(qLearning->startByFile());

Anyboy can help me?

Original issue reported on code.google.com by regis.cl...@gmail.com on 28 Feb 2013 at 4:30

GoogleCodeExporter commented 9 years ago
You have a char* line but it doesn't point to anything. When you call getline 
you should have a buffer already allocated.

Try using "char line[257];"

Original comment by AHeinerm on 1 Mar 2013 at 9:41