Jump to content

My System Error


Go to solution Solved by Kori,

Recommended Posts

Hello Guys,

Here is my Mount system via txt ( Serverside ) but i have a little proplem. The txt dont load but i dont know why.

Here my char_mount.cpp:

#include "stdafx.h"

#include "char_mount.h"
#include "char.h"
#include "log.h"
#include <fstream>
#include <sstream>

std::vector <AddNewMountsStruct> MountObjectList;

void LoadNewMounts(const char *fileName)
{
	std::string strdwVnum;
	std::ifstream File(fileName);

	if (File.fail())
	{
		sys_err("%s not found", fileName);
		return;
	}

	MountObjectList.clear();
	AddNewMountsStruct preload;
	while (!File.eof())
	{
		File >> strdwVnum;
		preload.dwVnum = atoi(strdwVnum.c_str());
		MountObjectList.push_back(preload);
	}
	sys_log(1, "Datei geladen");
}

bool AddNewMounts(int dwVnum)
{
	for (unsigned int i = 0; i < MountObjectList.size(); i++){
		if (MountObjectList[i].dwVnum == dwVnum){
			return true;
		}
	}
	return false;
}

char_mount.h


struct AddNewMountsStruct{
	int dwVnum;
};

void LoadNewMounts(const char *fileName);
bool AddNewMounts(int dwVnum);

 

 

here the funktion from the main.cpp 

int main(int argc, char **argv) )

LoadNewMounts("Mounts.txt");

 

 

the Mounts.txt looks like
 

0 // Character DMG
101 // example Mount
102 // example Mount
103 // example Mount

 

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Solution
31 minutes ago, Shelby said:

for load the file dude,

char YourFileName[256+1];

snprintf(YourFileName, sizeof(YourFileName), "yourfilename.txt");

and open it, etc..

sorry i dont understand you now :/
 

 

edit:

 

My new main.cpp function:

 

LoadNewMounts();

 

char_mounts.h:
 

struct AddNewMountsStruct{
	int dwVnum;
};

void LoadNewMounts();
bool AddNewMounts(int dwVnum);

char_mount.cpp:

 

#include "stdafx.h"
#include "locale_service.h"
#include "char_mount.h"
#include "char.h"
#include "log.h"
#include <fstream>
#include <sstream>
using namespace std;

std::vector <AddNewMountsStruct> MountObjectList;

void LoadNewMounts()
{
	char szFileName[256];
	snprintf(szFileName, sizeof(szFileName), "%s/Mounts.txt", LocaleService_GetBasePath().c_str());
	string strdwVnum;
	ifstream File(szFileName);

	if (!File.is_open()) {
		fprintf(stderr, "Failed to Load  %s/Mounts.txt\n", LocaleService_GetBasePath().c_str());
		sys_err("Failed to  %s/Mounts.txt", LocaleService_GetBasePath().c_str());
		return;
	}

	MountObjectList.clear();
	AddNewMountsStruct preload;
	while (!File.eof())
	{
		File >> strdwVnum;
		preload.dwVnum = atoi(strdwVnum.c_str());
		MountObjectList.push_back(preload);
	}
	sys_log(1, "Datei geladen");
}

bool AddNewMounts(int dwVnum)
{
	for (unsigned int i = 0; i < MountObjectList.size(); i++){
		if (MountObjectList[i].dwVnum == dwVnum){
			return true;
		}
	}
	return false;
}

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.