← cproj

insert hash

492eab4637354be2bfe3f429473700c3de949093 · Ovidiu · Jul 5, 2019 14:41

+21 −4 · 2 files changed

  • mylib/src/myhash.c +1 −1
  • mylib/test/t_hash.c +20 −3
diff --git a/mylib/src/myhash.c b/mylib/src/myhash.c
index 9e1e749..a7b2b17 100644
--- a/mylib/src/myhash.c
+++ b/mylib/src/myhash.c
@@ -211,7 +211,7 @@ ssize_t readLine(char *buf, size_t sz, char *fn, off_t 	*offset){
 	/* number of characetrs  */
 	ssize_t nchr = 0;
 
-  /* pointer to chars initialize to null */
+    /* pointer to chars initialize to null */
 	char *p  = NULL;
 
 	/* position fd & read line */
diff --git a/mylib/test/t_hash.c b/mylib/test/t_hash.c
index b35c556..626f471 100644
--- a/mylib/test/t_hash.c
+++ b/mylib/test/t_hash.c
@@ -76,14 +76,31 @@ int main(int argc, char** argv){
     off_t offset = 0;
     ssize_t len = 0;
     size_t i = 0;
-		char *token;
+
+	char *token;
+	char *key;
+	char *value;
+
     /* using open/read, read each line in file into 'line' */
     while ((len = readLine (line, 128, "../testdata" , &offset)) != -1) {
 			//strtok(line,":");
 			//printf (" line[%2zu] : %s (%zd chars)\n", i++, line, len);
 			token = strtok(line,":");
-		 		while( token != NULL ) {
-      		printf( " %s\n", token );
+			while( token != NULL ) {
+					i++;
+			if( i & 1 ) {
+				//printf("%s",token+1);
+				char *key = token;
+				printf("%s\n", key);
+				//printf("if\n");
+
+			} else {
+				char *value = token;
+				printf("%s\n", value);
+				//printf("else\n");
+			printf("outside \n");
+			h_insert(tableResult, key, value);
+			}
       		token = strtok(NULL, ":");
    			}