פונקציות ורשימות

Ron 417

New member
פונקציות ורשימות

יש לי בעיה עפ הפונקציה הבאה:
void update_species(Class *head_c,char common[],char latin[],char section[], int pop,double risk) { char genus_name[50]; Genus *temp_g; Class *temp_c; Species *temp_s; if (latin[0]=='\0'&&section[0]!='\0') // CASE 2 = no genus name for (temp_c=head_c;temp_c;temp_c=temp_c->next) if (!strcmp(temp_c->name,section)) for (temp_g=temp_c->down;temp_g;temp_g=temp_g->next) for (temp_s=temp_g->down;temp_s;temp_s=temp_s->next) if (!strcmp(temp_s->common_name,common)){ temp_s->population_size=pop; temp_s->risk_factor=risk; return; }​
אני לא חושב המבנים אמורים לעניין אתכם יותר מדי ,מכיוון שהבעיה בכלליות היא בלולאת הFOR. מה שקורה הוא ששמתי תנאי עצירה בניסוח : temp_g {הבעיה מתקיימת בשורה הרביעית של הבלוק המחובר} ,שזה אומר ש''כל עוד לא הגעת לNULL'' ,אבל העניין שהוא כן מגיע לNULL ,אבל לא מתייחס לתנאי העצירה . יש למישהו רעיון מה הבעיה ? תודה
 

Ron 417

New member
תיקון תיקון

זו הפונקציה הנכונה :
void update_species(Class *head_c,char common[],char latin[],char section[], int pop,double risk) { char genus_name[50]; Genus *temp_g; Class *temp_c; Species *temp_s; if (section[0]=='\0'&&latin[0]!='\0') // CASE 3 = no section for (temp_c=head_c;temp_c;temp_c=temp_c->next) for (temp_g=temp_c->down;temp_g;temp_g=temp_g->next) if (!strcmp(temp_g->name,genus_name)) <<<-------------------------- פה הבעיה for (temp_s=temp_g->down;temp_s;temp_s=temp_s->next) if (!strcmp(temp_s->common_name,common)){ temp_s->population_size=pop; temp_s->risk_factor=risk; return; } }​
 
למעלה