Browse Source

done w/ memory leaks, -20%

Iman Anwarzai 1 year ago
parent
commit
36e8f827d8
8 changed files with 12 additions and 9 deletions
  1. 2 2
      board.c
  2. BIN
      board.o
  3. BIN
      boggle
  4. 2 2
      scoreboard.c
  5. BIN
      scoreboard.o
  6. 2 2
      user.c
  7. BIN
      user.o
  8. 6 3
      users.txt

+ 2 - 2
board.c

@@ -137,13 +137,13 @@ int main () {
 	createLL(head);
 	User_s * head_s = malloc(sizeof(User_s));
 	head_s->score = 0;
-	char name[9];
+	char * name = malloc(9);
 	FILE * f = fopen("users.txt", "r");
 	int x, y, z;
 	for(int i = 0; i < user; i++)
 		fscanf(f, "%s %d %d %d", name, &x, &y, &z);
 	fclose(f);
-	head_s->name = malloc(sizeof(char)*50);
+	head_s->name = calloc(1, sizeof(char)*50);
 	strcpy(head_s->name, name);
 	//printf("%s\n", name);
 	head_s->next = NULL;

BIN
board.o


BIN
boggle


+ 2 - 2
scoreboard.c

@@ -8,7 +8,7 @@ void displayScoreboard(User_s * head){
         while(p){
 	//	printf("p\n");	
 		int s = p->score;
-		char * name = malloc(9);
+		char * name = calloc(1, 9);
 		strcpy(name, p->name);
                 printf("%s \t %d\n", name, s);
                 //printf("one\n");
@@ -65,7 +65,7 @@ void addUser(User_s * head, int user, int score){
                 temp = temp->next;
         }
         User_s * new_user = malloc(sizeof(User_s ));
-        new_user->name = malloc(9);
+        new_user->name = calloc(1, 9);
 	strcpy(new_user->name, name);
 	new_user->score = score;
 	new_user->next = NULL;

BIN
scoreboard.o


+ 2 - 2
user.c

@@ -53,7 +53,7 @@ int userNumberInFile(char * str){
                         return c;
         }
 	fclose(userList_r);
-	free(name);
+	//free(name);
         return -1;
 }
 int userExists(char * str){
@@ -78,7 +78,7 @@ int userLogin(){
 		printf("Welcome new user!\n");
 		fprintf(userList_a, "%s %d %d %d\n", user, 0, 0, 0);
 	}
-	free(user);
+//	free(user);
 	fclose(userList_a);
 	int u = userNumberInFile(user);
 	return u;

BIN
user.o


+ 6 - 3
users.txt

@@ -1,7 +1,7 @@
-iman 9 130 88
+iman 9 145 96
 alena 4 8 7
 ella 7 15 10
-ale 1 10 2
+ale 2 11 4
 aya 0 3 0
 cayleigh 1 2 2
 athena 0 0 0
@@ -11,7 +11,10 @@ newuser 0 0 0
 anu 3 8 10
 ismael 0 1 0
 anushka 0 0 0
-marina 3 2 5
+marina 3 4 6
 stoney 2 1 2
 ben 0 7 0
 akarsh 1 1 1
+aaa 0 0 0
+bbb 0 0 0
+aaaa 0 0 0