scoreboard.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "boggle.h"
  5. void displayScoreboard(User_s * head){
  6. printf("Scoreboard\n----------\n");
  7. User_s * p = head; //->next;
  8. while(p){
  9. // printf("p\n");
  10. int s = p->score;
  11. char * name = calloc(1, 9);
  12. strcpy(name, p->name);
  13. printf("%s \t %d\n", name, s);
  14. //printf("one\n");
  15. p = p->next;
  16. //printf("two\n");
  17. free(name);
  18. }
  19. // printf("done displaying\n");
  20. }
  21. /*void createLL_s(User_s* head){
  22. FILE * userList_c;
  23. //userList_c = fopen("users.txt", "r");
  24. char name[9];
  25. //fscanf(userList_c, "%s ", name);
  26. //User_s * head;
  27. head->name = malloc(strlen(name) + 1);
  28. strcpy(head->name, name);
  29. head->score = 0;
  30. fclose(userList_c);
  31. //return head;
  32. }*/
  33. void freeLL_s(User_s * head){
  34. User_s * curr = head;
  35. while(curr){
  36. // printf("%s about to be freed\n", curr->name);
  37. free(curr->name);
  38. User_s * temp = curr;
  39. curr = curr->next;
  40. // printf("done freeing name\n");
  41. free(temp);
  42. }
  43. }
  44. /*void freeLL(User * head){
  45. User * curr = head;
  46. while(curr != NULL){
  47. free(curr->name);
  48. User * temp = curr;
  49. curr = curr->next;
  50. free(temp);
  51. }
  52. }*/
  53. void addUser(User_s * head, int user, int score){
  54. FILE* userList_r;
  55. userList_r = fopen("users.txt", "r");
  56. char name[9];
  57. int a, b, c;
  58. for(int i = 0; i < user; i++){
  59. fscanf(userList_r, "%s %d %d %d", name, &a, &b, &c);
  60. }
  61. User_s * temp = head;
  62. while(temp->next){
  63. temp = temp->next;
  64. }
  65. User_s * new_user = malloc(sizeof(User_s ));
  66. new_user->name = calloc(1, 9);
  67. strcpy(new_user->name, name);
  68. new_user->score = score;
  69. new_user->next = NULL;
  70. temp->next = new_user;
  71. //printf("added new user\n");
  72. fclose(userList_r);
  73. }