944,120 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 333
  • C RSS
Nov 1st, 2009
0

debugger help

Expand Post »
hi everyone, i have a program code here, its working, but as soon as im trying to add results debugger breaks after adding score, can anyone help me to fix this problem. Program is working ok. heres the code:
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void addTeam(char[50], int);
  5. void calculateResult(int, int, int, int);
  6.  
  7. char newTeam[50];
  8. int menuChoice = 0;
  9. int numOfTeams = 0;
  10. int team1, team2, team1Score, team2Score;
  11.  
  12. typedef struct
  13. {
  14. char name[50];
  15. int points, goalsFor, goalsAgainst, played, won, lost, drawn;
  16. } team;
  17.  
  18. team teams[12];
  19.  
  20. void sortTable(team[]);
  21.  
  22. int main(void)
  23. {
  24. int i;
  25. while (menuChoice != 4)
  26. {
  27. printf("Football League\n\n");
  28. printf("1. Add team\n");
  29. printf("2. Display league table\n");
  30. printf("3. Add result\n");
  31. printf("4. Quit\n");
  32. scanf("%d", &menuChoice);
  33.  
  34. if (menuChoice == 1)
  35. {
  36. if (numOfTeams == 11)
  37. printf("Error: Maximum amount of teams has been entered");
  38. else
  39. {
  40. printf("Add new team\n");
  41. fgets(newTeam, sizeof(newTeam), stdin);
  42. newTeam[strlen(newTeam)-1] = '\0';
  43. fgets(newTeam, sizeof(newTeam), stdin);
  44. newTeam[strlen(newTeam)-1] = '\0';
  45. addTeam(newTeam, numOfTeams);
  46. numOfTeams++;
  47. printf("\nNew team added\n");
  48. }
  49. }
  50. else if (menuChoice == 2)
  51. {
  52. printf("\t\tP\tW\tD\tL\tF\tA\tT\n\n\n");
  53. for ( i = 0; i < 12; i++)
  54. {
  55. printf("%s\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
  56. teams[i].name, teams[i].played, teams[i].won,teams[i].drawn,
  57. teams[i].lost, teams[i].goalsFor, teams[i].goalsAgainst,
  58. teams[i].points);
  59. }
  60. }
  61. else if (menuChoice == 3)
  62. {
  63. printf("Enter first team playing:\n");
  64. scanf("%d", &team1);
  65. printf("Enter second team playing:\n");
  66. scanf("%d", &team2);
  67. printf("Enter first teams score:\n");
  68. scanf("%d", &team1Score);
  69. printf("Enter second teams score:\n");
  70. scanf("%d", &team2Score);
  71. calculateResult(team1, team2, team1Score, team2Score);
  72. }
  73.  
  74. }
  75. return 0;
  76. }
  77.  
  78. void addTeam(char *teamName, int i)
  79. {
  80. strcpy(teams[i].name, teamName);
  81. teams[i].points = 0;
  82. teams[i].goalsFor = 0;
  83. teams[i].goalsAgainst = 0;
  84. teams[i].played = 0;
  85. teams[i].won = 0;
  86. teams[i].lost = 0;
  87. teams[i].drawn = 0;
  88. }
  89.  
  90. void calculateResult(int t1, int t2, int t1R, int t2R)
  91. {
  92. if (t1R > t2R)
  93. {
  94. teams[(t1-1)].points+=3;
  95. teams[(t1-1)].won++;
  96. teams[(t2-1)].lost++;
  97. }
  98. else if (t2R > t1R)
  99. {
  100. teams[(t2-1)].points+=3;
  101. teams[(t2-1)].won++;
  102. teams[(t1-1)].lost++;
  103. }
  104. else
  105. {
  106. teams[(t2-1)].points++;
  107. teams[(t1-1)].points++;
  108. teams[(t1-1)].drawn++;
  109. teams[(t2-1)].drawn++;
  110. }
  111. teams[(t1-1)].goalsFor+=t1R;
  112. teams[(t2-1)].goalsFor+=t2R;
  113. teams[(t1-1)].goalsAgainst+=t2R;
  114. teams[(t2-1)].goalsAgainst+=t1R;
  115. teams[(t1-1)].played++;
  116. teams[(t2-1)].played++;
  117.  
  118. sortTable(teams);
  119. }
  120.  
  121. void sortTable(team teams1[])
  122. {
  123. team temp[1];
  124. int i, j;
  125. for ( i = 0; i < 12; i++)
  126. {
  127. for ( j = 11; j >=0; j--)
  128. {
  129. if (teams1[j].points > teams1[(j-1)].points)
  130. {
  131. temp[1] = teams1[(j-1)];
  132. teams1[(j-1)] = teams1[j];
  133. teams1[j] = temp[1];
  134. }
  135. }
  136. }
  137. }
thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
dinamit875 is offline Offline
48 posts
since Mar 2009
Nov 1st, 2009
0
Re: debugger help
Which debugger are you using?
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is online now Online
2,198 posts
since Jan 2008
Nov 1st, 2009
0
Re: debugger help
  1. team temp[1];
This has only one element: temp[0] .
temp[1] = teams1[(j-1)];
teams1[(j-1)] = teams1[j];
teams1[j] = temp[1];
Last edited by Dave Sinkula; Nov 1st, 2009 at 7:20 pm.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 2nd, 2009
0
Re: debugger help
Click to Expand / Collapse  Quote originally posted by gerard4143 ...
Which debugger are you using?
im using devc++
Reputation Points: 10
Solved Threads: 0
Light Poster
dinamit875 is offline Offline
48 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Can embedded server be accessed by external applications?
Next Thread in C Forum Timeline: C program to remove duplicates





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC