added comments and todos
This commit is contained in:
parent
8811598366
commit
e6e218f3c4
43
vendorInfo.c
43
vendorInfo.c
|
@ -47,10 +47,12 @@ int main()
|
||||||
|
|
||||||
while ((fgets(file_buffer, 50, fp) != NULL) && (index <= MAX_VENDORS))
|
while ((fgets(file_buffer, 50, fp) != NULL) && (index <= MAX_VENDORS))
|
||||||
{
|
{
|
||||||
|
/* TO-DO: VALIDATE FILE DATA */
|
||||||
char *token = strtok(file_buffer, " ");
|
char *token = strtok(file_buffer, " ");
|
||||||
strncpy(vendors[index].vendor_name, token, strlen(token) + 1);
|
strncpy(vendors[index].vendor_name, token, strlen(token) + 1);
|
||||||
|
|
||||||
token = strtok(NULL, " ");
|
token = strtok(NULL, " ");
|
||||||
|
/* TO-DO: VALIDATE MERCHANDISE BY PUTTING EVERYTHING AS LOWERCASE*/
|
||||||
strncpy(vendors[index].merchandise, token, strlen(token) + 1);
|
strncpy(vendors[index].merchandise, token, strlen(token) + 1);
|
||||||
|
|
||||||
token = strtok(NULL, " ");
|
token = strtok(NULL, " ");
|
||||||
|
@ -82,26 +84,31 @@ int main()
|
||||||
|
|
||||||
printf("%-50s %s\n", vendor_info, vendor_stock);
|
printf("%-50s %s\n", vendor_info, vendor_stock);
|
||||||
}
|
}
|
||||||
|
|
||||||
char user_purchase[50];
|
|
||||||
|
|
||||||
char query[100];
|
char user_query[100];
|
||||||
read_input(query, 100);
|
read_input(user_query, 100);
|
||||||
|
|
||||||
int query_length = strlen(query);
|
// convert string to lowercase - each character one by one
|
||||||
|
int user_query_length = strlen(user_query);
|
||||||
for (int i = 0; i < query_length; i++)
|
for (int i = 0; i < user_query_length; i++)
|
||||||
{
|
{
|
||||||
query[i] = tolower(query[i]);
|
user_query[i] = tolower(user_query[i]);
|
||||||
};
|
};
|
||||||
|
|
||||||
search(query, vendors, total_vendors);
|
search(user_query, vendors, total_vendors);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free(file_buffer);
|
free(file_buffer);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
custom read input function
|
||||||
|
str = string itself
|
||||||
|
n = max amount of characters that the function is able to read into buffer
|
||||||
|
|
||||||
|
reads one character at a time into buffer and adds a null terminator when finish reading
|
||||||
|
*/
|
||||||
int read_input(char str[], int n)
|
int read_input(char str[], int n)
|
||||||
{
|
{
|
||||||
int ch, i = 0;
|
int ch, i = 0;
|
||||||
|
@ -118,6 +125,14 @@ int read_input(char str[], int n)
|
||||||
return i;
|
return i;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Search function
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- query: search query
|
||||||
|
- vendors: the vendor table
|
||||||
|
- total_vendors: the amount of vendors
|
||||||
|
*/
|
||||||
int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vendors)
|
int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vendors)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -142,7 +157,15 @@ int search(char query[], struct vendor_item vendors[MAX_VENDORS], int total_vend
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
int purchase(struct vendor_item vendors[MAX_VENDORS], char str[], int amount)
|
/*
|
||||||
|
Purchase function
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- item: The item that the user is purchasing
|
||||||
|
- amount: How many items that the user is purchasing
|
||||||
|
- vendors: vendor table
|
||||||
|
*/
|
||||||
|
int purchase(char item[], int amount, struct vendor_item vendors[MAX_VENDORS])
|
||||||
{
|
{
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue