-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashbuilder.c
More file actions
46 lines (42 loc) · 1.05 KB
/
Copy pathhashbuilder.c
File metadata and controls
46 lines (42 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Program to create and inventory hashfile by applying the transactions listed in
* a data file.
* Author: Simon Haile
* Date: May 30, 2017
*/
#include "hashfile.h"
#include "product.h"
#include "price.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX_LINE_LEN 1024
int main(int argc, char *argv[]){
if(argc < 3){
printf("Usage: please type the inventory file name followed by the desired file name fo the hash file.\n");
exit(0);
}
size_t len = MAX_LINE_LEN;
char *inventory = argv[1];
char *hashfile_name = argv[2];
char *line = NULL;
FILE *fp = NULL;
if(access(inventory, F_OK) != -1){
fp = fopen(inventory,"r+");
}
else{
printf("Cound not find file named: %s\n",inventory);
exit(0);
}
//create a new hash file using hashfile_name
FILE *hash_fp = create_hashfile(hashfile_name);
product_t new_prod;
//read all lines from the inverntory_file
while( getline(&line, &len,fp) != -1){
line[strlen(line)-1] = '\0';
read_product(line, &new_prod);
add_item(hash_fp,new_prod);
}
display_hashfile(hash_fp);
}