I'm having Bus error: 10 when I call the same function twice or more times. For example, I've a function to change a word to lowercase, and if I call it more than one time, it gives me the bus error.
while(bla != NULL){
if(bla->id != NULL && bla->type != NULL && bla->second_type != NULL){
char * id_print = strtolower(bla->id);
//char * type_print = strtolower(bla->type);
//char * second_type_print = strtolower(bla->second_type);
printf("%s\t_%s_\t%s\n", id_print, bla->type, bla->second_type);
}
else if(bla->id != NULL && bla->type != NULL){
char * id_print = strtolower(bla->id);
//char * type_print = strtolower(bla->type);
printf("%s\t_%s_\n", id_print, bla->type);
}
bla = bla->next_symbol_entry;
}
If I have the function call on comment, I don't have the error. But:
while(bla != NULL){
if(bla->id != NULL && bla->type != NULL && bla->second_type != NULL){
char * id_print = strtolower(bla->id);
char * type_print = strtolower(bla->type);
char * second_type_print = strtolower(bla->second_type);
printf("%s\t_%s_\t%s\n", id_print, type_print, second_type_print);
}
else if(bla->id != NULL && bla->type != NULL){
char * id_print = strtolower(bla->id);
char * type_print = strtolower(bla->type);
printf("%s\t_%s_\n", id_print, type_print);
}
bla = bla->next_symbol_entry;
}
if I uncomment the function calls, this gives me the Bus error.
Can you help me to understand why?
The strtolower function is:
char * strtolower(char * str){
char * string = str;
if(str){
for(; *str; ++str)
*str = tolower(*str);
}
return string;
}