From caab15610499072b2871606501f76eaaf15563e4 Mon Sep 17 00:00:00 2001
From: Anqi Chen <a.chen49@student.unimelb.edu.au>
Date: Mon, 29 Apr 2019 21:15:40 +1000
Subject: [PATCH] swapp users fixed

---
 img.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/img.c b/img.c
index 79bbeb3..547d7bf 100644
--- a/img.c
+++ b/img.c
@@ -163,7 +163,8 @@ struct User* find_curr(struct User* user_arr[], char* buff)
 // the user in arrsy if not this one, then should be that one
 struct User* the_other_user(struct User* curr_user, struct User* user_arr[]){
     for(int i=0; i<2; i++){
-        if (user_arr[i]!=curr_user){
+        if (user_arr[i]->userID!=curr_user->userID){
+            printf("the other user id is %d\n", user_arr[i]->userID);
             return user_arr[i];
         }
     }
@@ -183,8 +184,10 @@ bool match(char* w1, char** w2, int n_word){
 
 // only load page
 void simple_load_html(char* html, int sockfd, char* buff, int n, struct User* curr_user){
+    
     struct stat st;
     stat(html, &st);
+    // print into buff
     n = sprintf(buff, HTTP_200_FORMAT, st.st_size,curr_user->userID);
     if (write(sockfd, buff, n) < 0)
             {
@@ -271,7 +274,7 @@ void edit_load_html(char* html, int sockfd, char* buff, char* newword,struct Use
 // read the words into the curr_user->keywords
 void record_keyword(struct User* curr_user, char *new_guess){
     for (int i=0; i<=curr_user->n_word; i++){
-
+        // add to the first NULL bit and malloc 
         if(curr_user->keywords[curr_user->n_word]==NULL){
             curr_user->keywords[curr_user->n_word] = malloc((1 + strlen(new_guess)) * sizeof(char*));
             strcpy(curr_user->keywords[curr_user->n_word],new_guess);
-- 
GitLab