debugger help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 25
Reputation: dinamit875 is an unknown quantity at this point 
Solved Threads: 0
dinamit875 dinamit875 is offline Offline
Light Poster

debugger help

 
0
  #1
Nov 1st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 373
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 47
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz
 
0
  #2
Nov 1st, 2009
Which debugger are you using?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,400
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 247
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
0
  #3
Nov 1st, 2009
  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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 25
Reputation: dinamit875 is an unknown quantity at this point 
Solved Threads: 0
dinamit875 dinamit875 is offline Offline
Light Poster
 
0
  #4
Nov 2nd, 2009
Originally Posted by gerard4143 View Post
Which debugger are you using?
im using devc++
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC