upgrade program.c
This commit is contained in:
parent
7e9c26ead7
commit
359fcbc229
@ -13,10 +13,10 @@ char* convert(char* input)
|
||||
{
|
||||
int inplen = strlen(input);
|
||||
char* res = (char*)malloc(inplen * sizeof(char*));
|
||||
memset(res,0,inplen);
|
||||
strcpy(res,input);
|
||||
for (int i = 0; i < inplen; i++)
|
||||
{
|
||||
switch (res[i])
|
||||
switch (input[i])
|
||||
{
|
||||
case '0': res[i] = 'o'; break;
|
||||
case '1': res[i] = 'i'; break;
|
||||
@ -28,29 +28,31 @@ char* convert(char* input)
|
||||
case '7': res[i] = 't'; break;
|
||||
case '8': res[i] = 'b'; break;
|
||||
case '9': res[i] = 'q'; break;
|
||||
default: res[i] = tolower(res[i]);
|
||||
case '\n': res[i] = '\0'; break;
|
||||
default: res[i] = tolower(res[i]); break;
|
||||
}
|
||||
}
|
||||
res[inplen] = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
int search(char* find, int itemsc, struct pizza* menu)
|
||||
int* search(char* find, int itemsc, struct pizza* menu, int* outC)
|
||||
{
|
||||
int* res = (int*)malloc(itemsc*sizeof(int*));
|
||||
memset(res,0,itemsc);
|
||||
char* findtlw = convert(find);
|
||||
for (int i = 0; i < itemsc; i++)
|
||||
{
|
||||
char* conved = convert(menu[i].name);
|
||||
if(strstr(conved,findtlw) != NULL)
|
||||
{
|
||||
free(conved);
|
||||
free(findtlw);
|
||||
return i;
|
||||
res[*outC] = i;
|
||||
(*outC)++;
|
||||
}
|
||||
free(conved);
|
||||
}
|
||||
free(findtlw);
|
||||
return -1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int main()
|
||||
@ -94,17 +96,18 @@ int main()
|
||||
break;
|
||||
}
|
||||
}
|
||||
int item = search(find,itemc,menu);
|
||||
if(item == -1)
|
||||
int sitemc = 0;
|
||||
int* items = search(find,itemc,menu,&sitemc);
|
||||
for (int i = 0; i < sitemc; i++)
|
||||
{
|
||||
return 0;
|
||||
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
||||
}
|
||||
printf("%s\n%.2f\n", menu[item].name, menu[item].price);
|
||||
printf("Nacitanych %d poloziek.\n", itemc);
|
||||
for (int i = 0; i < itemc; i++)
|
||||
{
|
||||
free(menu[i].name);
|
||||
}
|
||||
free(items);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user