הפונקציה:
// make a purchase by one team of one player void OrderPlayer (node *lHead, team teamS{TEAMS}, int TeamNumber, int pRol, int pPay) { node *temp; if (teamS.budjet < pPay) // checking if the team have the amount of money they are willing to pay printf ("Sorry, this team doesn't have much money!\n"); else // if the team have enough money in order to pay the specified amount { while(lHead != NULL) // keep printing while there're still more nodes to print if ((lHead -> rol == pRol) && (lHead -> price <= pPay)) // test if current player fits the requirements { temp = (node*) malloc (sizeof (node)); // create new node to keep the player address temp = lHead; // keep current player's node temp -> tnext = teamS{TeamNumber}.players; // updating temp's next to be the team's players pointer teamS{TeamNumber}.players = temp; // putting the temp instead of the older players pointer of the team teamS{TeamNumber}.budjet -= pPay; // updating the team's balance after the purchase printf ("%s", temp -> name); return; } else lHead = lHead -> next; } }
|
(במקום סוגריים מסולסלים, אמורים להיות מרובעים בתוך הקוד)
עכשיו הבעיה היא כזו
אפשר לראות שאחד הפרמטרים הוא מערך בשם teamS, שבעצם מקבל רשימת קבוצות בעלות פרמטרים שונים, אחד הפרמטרים הוא מצביע לאיבר כמו הlHead באותה פונקציה.
אם אני יוצר את הרשימה כמו שעשיתי פה, כלומר teamS{TeamNumber}.players = temp
פשוט לא קורה כלום, עקבתי אחרי כל שלב, ופשוט כלום לא קורה פה.
לעומת זאת, אם במקום מערך, אני משתמש במשתנה בודד, זה עובד.
יש לכם מושג למה זה ככה?
תודה רבה
