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