added functions
This commit is contained in:
parent
2944612155
commit
1f5d50221a
Binary file not shown.
31
vendorInfo.c
31
vendorInfo.c
|
@ -38,7 +38,9 @@ struct purchase_r
|
|||
};
|
||||
|
||||
/* FUNCTION DECLARATION */
|
||||
int read_input(char str[], int n);
|
||||
int read_input(char str[], size_t n);
|
||||
char *strnlower(char *s, size_t n);
|
||||
int validate_data(struct vendor vendors[MAX_VENDORS]);
|
||||
|
||||
struct search_r search
|
||||
(
|
||||
|
@ -129,11 +131,8 @@ int main()
|
|||
|
||||
// convert string to lowercase - each character one by one
|
||||
int user_query_length = strlen(user_query);
|
||||
for (int i = 0; i < user_query_length; i++)
|
||||
{
|
||||
user_query[i] = tolower(user_query[i]);
|
||||
};
|
||||
|
||||
strnlower(user_query, user_query_length);
|
||||
|
||||
struct search_r item = search(user_query, vendors, total_vendors);
|
||||
if(item.status == 0)
|
||||
{
|
||||
|
@ -177,13 +176,13 @@ int main()
|
|||
|
||||
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[], size_t n)
|
||||
{
|
||||
int ch, i = 0;
|
||||
|
||||
while ((ch = getchar()) != '\n')
|
||||
{
|
||||
if (i < n)
|
||||
if (i < (int)n)
|
||||
{
|
||||
str[i++] = ch;
|
||||
}
|
||||
|
@ -193,6 +192,22 @@ int read_input(char str[], int n)
|
|||
return i;
|
||||
};
|
||||
|
||||
/*
|
||||
strnlower: Convert string to lowercase
|
||||
|
||||
Parameters:
|
||||
- s: String
|
||||
- n: Length of string
|
||||
|
||||
*/
|
||||
char *strnlower(char *s, size_t n)
|
||||
{
|
||||
for (int i = 0; i < (int) n; i++)
|
||||
{
|
||||
s[i] = tolower(s[i]);
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Search function
|
||||
|
||||
|
|
Loading…
Reference in New Issue