Iman Anwarzai 1 year ago
parent
commit
432b36a1f0
11 changed files with 41 additions and 18 deletions
  1. 2 2
      Makefile
  2. 17 5
      board.c
  3. BIN
      board.o
  4. BIN
      boggle
  5. 0 1
      boggle.h
  6. BIN
      dictionaryChecker.o
  7. 12 3
      scoreboard.c
  8. BIN
      scoreboard.o
  9. 3 1
      user.c
  10. BIN
      user.o
  11. 7 6
      users.txt

+ 2 - 2
Makefile

@@ -1,12 +1,12 @@
 CC = gcc
-CFLAGS = -Wall -std=c99
+CFLAGS = -g  -Wall -std=c99
 DEPS = boggle.h
 
 %.o: %.c $(DEPS)
 	$(CC) -c -o $@ $< $(CFLAGS)
 
 boggle: board.o user.o scoreboard.o dictionaryChecker.o 
-	$(CC) -o boggle board.o user.o scoreboard.o dictionaryChecker.o
+	$(CC) $(CFLAGS)  -o boggle board.o user.o scoreboard.o dictionaryChecker.o
 
 clean:
 	rm boggle

+ 17 - 5
board.c

@@ -64,11 +64,16 @@ int wordval(char * s){
 }
 int exists = 0;
 void isaword_helper(char ** arr, int ** passed, int i, int j, char * str, char * goal){
-        passed[i][j] = 1;
+        //printf("%d\n", exists);
+	//printf("%d\n", passed[i][j]);
+	//display(arr);
+	//printf("%s\n", str);
+	passed[i][j] = 1;
         str[strlen(str)] = arr[i][j];
         if(strcmp(str, goal) == 0){
                 exists = 1;
-                return;
+                //printf("the word exists!\n");
+		return;
         }
         for (int r = i-1; r <= i+1 && r < 4; r++)
                 for (int c = j-1; c <= j+1 && c < 4; c++)
@@ -77,6 +82,7 @@ void isaword_helper(char ** arr, int ** passed, int i, int j, char * str, char *
                                         isaword_helper(arr, passed, r, c, str, goal);
         str[strlen(str) - 1] = '\0';
         passed[i][j] = 0;
+	//printf("%d\n", exists);
 }
 int isaword(char ** arr, char * goal){
         int ** temp = malloc(sizeof(int*) * 4);
@@ -86,12 +92,13 @@ int isaword(char ** arr, char * goal){
                 for(int y = 0; y < 4; y++)
                           temp[x][y] = 0;
 
-        char * string = malloc(1024);
+        char * string = calloc(1, 1024);
         for(int i = 0; i < 4; i++)
                 for(int j = 0; j < 4; j++)
                         isaword_helper(arr, temp, i, j, string, goal);
         freeall(temp);
         //free(temp);
+        //strcpy(string, '\0');
         free(string);
         return exists;
 
@@ -125,6 +132,7 @@ int main () {
         int score = 0;
 	system("clear");
 	int user = userLogin();
+	//printf("%d\n", user);
 	User * head = malloc(sizeof(User));
 	createLL(head);
 	User_s * head_s = malloc(sizeof(User_s));
@@ -134,7 +142,10 @@ int main () {
 	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);
 	strcpy(head_s->name, name);
+	//printf("%s\n", name);
 	head_s->next = NULL;
 	char ** words = malloc(sizeof(char*) * 50);
 	for(int i =0; i < 50;i++)
@@ -152,7 +163,7 @@ int main () {
 			if(strcmp(entered, "y") == 0){
 				userUpdate(head, user, score);
 				displayScoreboard(head_s);
-		       		
+		       		//printf("%s\n", head_s->name);
 				free(entered);
 				break;
 			}
@@ -197,6 +208,7 @@ int main () {
 				words = malloc(sizeof(char * ) * 50);
 				for(int i =0; i < 50;i++)
 					words[i] = malloc(17);
+	//			createboard(arr);
 			}
 			free(entered);
 		}
@@ -248,7 +260,7 @@ int main () {
 	}
 	//displayScoreboard(head_s);
 	freeLL(head);
-	//freeLL_s(head_s);
+	freeLL_s(head_s);
 	for(int i = 0; i < 50; i++)
                free(words[i]);
         free(words);

BIN
board.o


BIN
boggle


+ 0 - 1
boggle.h

@@ -28,7 +28,6 @@ void userUpdate(User * head, int un, int s);
 void freeLL(User * head);
 void capitalize(char* s);
 int wordval(char * s);
-//int isaword(char ** arr, char * goal);
 void createLL_s(User_s* head);
 void freeLL_s(User_s * head);
 void displayScoreboard(User_s * head);

BIN
dictionaryChecker.o


+ 12 - 3
scoreboard.c

@@ -14,6 +14,7 @@ void displayScoreboard(User_s * head){
                 //printf("one\n");
 		p = p->next;
 		//printf("two\n");
+		free(name);
         }
 //	printf("done displaying\n");
 }
@@ -33,15 +34,23 @@ void displayScoreboard(User_s * head){
 void freeLL_s(User_s * head){
         User_s * curr = head;
         while(curr){
+//		printf("%s about to be freed\n", curr->name);
 		free(curr->name); 
-               //printf("%s about to be freed\n", curr->name);
 		User_s * temp = curr;
-		//free(temp->name);
-		//free(temp);
                 curr = curr->next;
+//		printf("done freeing name\n");
 		free(temp);
         }
 }
+/*void freeLL(User * head){
+        User * curr = head;
+        while(curr != NULL){
+                free(curr->name);
+                User * temp = curr;
+                curr = curr->next;
+                free(temp);
+        }
+}*/
                 
 void addUser(User_s * head, int user, int score){
         FILE* userList_r;

BIN
scoreboard.o


+ 3 - 1
user.c

@@ -44,7 +44,7 @@ void createLL(User * head){
 int userNumberInFile(char * str){
         FILE * userList_r;
         userList_r = fopen("users.txt", "r");
-        char name[9];
+        char * name = malloc(9);
         int hs, g, ts;
         int c = 0;
         while(fscanf(userList_r, "%s %d %d %d \n", name, &hs, &g, &ts) == 4){
@@ -53,6 +53,7 @@ int userNumberInFile(char * str){
                         return c;
         }
 	fclose(userList_r);
+	free(name);
         return -1;
 }
 int userExists(char * str){
@@ -77,6 +78,7 @@ int userLogin(){
 		printf("Welcome new user!\n");
 		fprintf(userList_a, "%s %d %d %d\n", user, 0, 0, 0);
 	}
+	free(user);
 	fclose(userList_a);
 	int u = userNumberInFile(user);
 	return u;

BIN
user.o


+ 7 - 6
users.txt

@@ -1,8 +1,8 @@
-iman 5 89 45
-alena 4 5 6
-ella 7 14 10
-ale 1 4 1
-aya 0 2 0
+iman 9 130 88
+alena 4 8 7
+ella 7 15 10
+ale 1 10 2
+aya 0 3 0
 cayleigh 1 2 2
 athena 0 0 0
 iman1 0 0 0
@@ -13,4 +13,5 @@ ismael 0 1 0
 anushka 0 0 0
 marina 3 2 5
 stoney 2 1 2
-ben 0 5 0
+ben 0 7 0
+akarsh 1 1 1