diff --git a/vendorInfo b/vendorInfo index c90780c..7b2cb41 100755 Binary files a/vendorInfo and b/vendorInfo differ diff --git a/vendorInfo.c b/vendorInfo.c index afd4f67..d7d3f88 100644 --- a/vendorInfo.c +++ b/vendorInfo.c @@ -6,6 +6,7 @@ #include #include +#include #define MAX_VENDORS 20 #define MAX_FILENAME_LENGTH 4096 @@ -37,10 +38,30 @@ int main() unsigned long file_size = ftell(fp); fseek(fp, 0, SEEK_SET); + // read file to buffer char *file_buffer = (char *) malloc(file_size); - fread(file_buffer, file_size, 1, fp); + int index = 0; - printf("%s", file_buffer); + while (fgets(file_buffer, 50, fp) != NULL) + { + char *token = strtok(file_buffer, " "); + strcpy(vendors[index].vendor_name, token); + + token = strtok(NULL, " "); + strcpy(vendors[index].merchandise, token); + + token = strtok(NULL, " "); + vendors[index].inventory_count = atoi(token); + + token = strtok(NULL, " "); + vendors[index].item_price_baht = atoi(token); + + index++; + } + + for (int i = 0; i < MAX_VENDORS; i++) { + printf("%d | %s %s %d %d\n", i, vendors[i].vendor_name, vendors[i].merchandise, vendors[i].inventory_count, vendors[i].item_price_baht); + } fclose(fp); free(file_buffer);