我有 Bus error: 10 当我调用同一个函数两次或更多次时。例如,我有一个将单词更改为小写的函数,如果我多次调用它,就会出现总线错误。
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;
}
如果我在评论中有函数调用,我没有错误。但:
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;
}
如果我取消注释函数调用,这会给我总线错误。
你能帮我理解为什么吗?
strtolower 函数是:
char * strtolower(char * str){
char * string = str;
if(str){
for(; *str; ++str)
*str = tolower(*str);
}
return string;
}