我有一個鏈接列表和一個setter函數。替換鏈接列表中的節點值
struct my_struct {
int value;
int type;
char *name;
struct my_struct *next;
};
struct my_struct *setValue(struct my_struct *s, char *name, int b) {
if(s!=NULL) {
while(s != NULL) {
if(strcmp(s->name,name) == 0) {
s->value = b;
}
s=s->next;
}
return s;
}
return NULL;
}
這裏,name是搜索關鍵字,b是s-> value的新值。爲什麼s-> value不能改變?在這個功能之後,輸出很奇怪。我無法理解,發生了什麼事。
爲什麼此函數返回始終爲NULL的指針?它應該返回什麼? – wildplasser