hi all,
i'm writing my c++ project and in visual studio everything goes good but when i'm compiling it on ubuntu many things get wrong. example:
int main (int argsNum, char* args[]){
Country* country = new Country("USA");
Military* military = new Military("Army",country);
Shalishut* shalishut = new Shalishut(military);
Manager* manager = Manager::GetInstance();
FileReader* fileReader = FileReader::GetInstance();
fileReader->ReadCityConfig(args,country);
fileReader->ReadRoadConfig(args,country);
fileReader->ReadMilitrayCampConfig(args,military);
military->ShowBases();
return 0;
}
void FileReader::ReadMilitrayCampConfig(char* args[], Military* military){
string line;
char inputFileName [MAX_FILE_NAME_LEN];
strcpy (inputFileName,args[3]);
ifstream myfile (inputFileName); //inputFileName
char* campName;
string cityName;
if (myfile.is_open()){
while (!myfile.eof()){ //until the end of file
getline (myfile,line); //separate each line.
if ((line.size() != 0) && (line[0] != '#')) {
campName = strtok(&line[0],",");
cityName = (string)strtok(NULL,",");
Shalishut::FixName(campName); Shalishut::FixName(&cityName[0]);
if (!(military->IsBaseExist(campName))){
if (military->GetCountry()->IsCityExist(cityName)){
Base* baseToAdd = new Base(campName,cityName);
if (baseToAdd != NULL){
military->AddBaseToMilitary(baseToAdd);
military->GetCountry()->FindCity(cityName)->AddBaseToCity(baseToAdd);
}
}
else cout << "ERROR: City named \"" << cityName << "\" does not exist, can't add base \"" << campName << "\" !" << endl<<endl;
}
else cout << "ERROR: Base Named \"" << campName << "\" is already exist in Military, can't create base!" << endl<<endl;
}
}
myfile.close();
}
else throw ExceptionMilitaryCampConfigFileFault(); /*cout << "ERROR: Unable to open MilitaryConfig file!"<< endl;*/
}
bool Country::IsCityExist(const string cityName){
map<string ,City*>::iterator itCities;
itCities = m_cities.find((string)cityName);
if (itCities != m_cities.end()) return true;
else return false;
}
void Shalishut::FixName(char* name){
int i;
name[0] = toupper(name[0]);
for (i=1 ; name[i] ; i++){
name[i] = tolower (name[i]);
}
}
}
The problem is that the program reads the cities and the roads, but when it reads the military camp i got:
" does not exist, can't add base "Hazerim" !
even though in the config file i have base in the same name. remind: in visual studio it works perfectly!