i signed with stars the 2 rows that are creating the problem.
the first row allocates memory for logfile, that will be used in the second signed row. at the second signed row there is a problem of segmentation fault. This is caused by the fact that "logfile" is not allocated. I'm am sure of this because if i allocate the memory in load() it works. However I want to allocate the memory in the constructor of the class and not in the method load().
I cannot understand why it does not work! This is my first time on linux and so maybe i'm doing something wrong!
Thank you, Marco
server::server(){
port = 0;
serverup = 0;
loaded = 0;
logfile = (char *) malloc(SERVER_PATHS_SIZE*sizeof(char)); //****************************
}
int server::load(int in_id, char *in_name, char *in_ip, int in_port,
char *in_rcon, char *in_logfile){
int err;
sprintf(name, "%s\x00", in_name);
sprintf(ip, "%s\x00", in_ip);
port = in_port;
sprintf(rcon, "%s\x00", in_rcon);
sprintf(logfile,"%s\x00", in_logfile); //**********************************
err = urt.set(ip, port, rcon);
if(err < 1){
printf("server::load(): error from urt.set()\n");
return 0;
}
printf("server::load(): server %d loaded!\n", id);
loaded = 1;
return 1;
}
logfileis declared. Is it a member variable of class server? Is it global? Making your examples stand-alone compilable is crucial for debugging.newis usually preferred overmallocstd::string?