In the code, when I print var_value, it shows its content but when I need to assign it later on the if else statements, it's empty only IN THE LAST IF and I have no idea why it is. If I delete the last statement, the other three pass without problems.
while ((read = getline(&line, &len, f)) != -1){
printf("%s\n", line);
char *token;
token = strtok(line, "=");
var_name = token;
/* Separate every line by the '=' character */
while( token != NULL ) {
var_value = token;
token = strtok(NULL, "=");
}
printf("%s\n", var_name);
printf("%s\n", var_value);
// Obtain the parameters
if (strcmp(var_name, "puerto") == 0) {
puerto = atoi(var_value);
parameters_count += 1;
} else if (strcmp(var_name, "tamano_tabla") == 0) {
tamano_tabla = atoi(var_value);
parameters_count += 1;
} else if (strcmp(var_name, "periodo_archivo") == 0) {
periodo_archivo = atoi(var_value);
parameters_count += 1;
} else if (strcmp(var_name, "archivo_tabla") == 0) {
printf("%s var val\n", var_value);
strcpy(archivo_tabla, strtok(var_value, "\n")); //Remove \n and copy to destination variable
parameters_count += 1;
printf("%s filetabla\n", archivo_tabla);
}
}
Edit: Results in console and after the final one, segmentation fault
puerto=1212
puerto
1212
archivo_tabla=tabla.xml
archivo_tabla
tabla.xml
tabla.xml
var val