problem reading string from file
Helo forums,
I'me trying to read config file, - here's my c code:
Code:
void GetConf(){
FILE* config_fp;
char line[MAX_LINE_LEN+1];
char* var_word;
printf("\nReading config...\n");
config_fp = fopen("them.conf","r");
while(fgets(line, MAX_LINE_LEN, config_fp) != NULL){
var_word=strtok(line, "\t =\n\r");
if(var_word != NULL && var_word[0]!='#'){
if(!strcmp(var_word,"hi_temp")){
var_word=strtok(NULL, "\t =\n\r");
hi_temp=atoi(var_word);
}
if (!strcmp(var_word,"lo_temp")){
var_word=strtok(NULL, "\t =\n\r");
lo_temp=atoi(var_word);
}
if (!strcmp(var_word,"log_file")){
var_word=strtok(NULL, "\t =\n\r");
log_file=var_word;
printf ("Value inside clause: %s\n",var_word);
}
}
}
printf ("Value outside clause: %s",log_file);
printf ("Done.\n");
}
Config file:
log_file=log
hi_temp=25
lo_temp=10
correction=20
Otput:
Reading config...
Value inside clause: log
Value outside clause: 600Done.
###################################
How does this happen? - why 'log_file' value suddenly becomes 600 ?