#include #include #include #include #define LINESIZE 100 struct pizza{ char name[LINESIZE]; float prize; }; //read menu int read_pizza(struct pizza* item){ char line1[LINESIZE]; char line2[LINESIZE]; memset(line1, 0, LINESIZE); memset(line2, 0, LINESIZE); char *l1 = fgets(line1,LINESIZE,stdin); //read first line(name) char *l2 = fgets(line2,LINESIZE,stdin); //read second line(price) float value = strtof(line2, &l2); //change char to float, because price is a nummber if(value == 0.0F){ return 0; } if(l1 != NULL && line1[1] != 0){ //check if array with name is not empty item->prize = value; strcpy(item->name, line1); return 1; } } //check every place where the string might be //if there isn't at first place, go to the second etc. int search_string(const char* heap, const char* needle){ int H = strlen(heap); int N = strlen(needle); int i = 0; for(i = 0; i <= H - N; i++){ int j; for(j = 0; j < N; j++){ if(heap[i+j] != needle[j]){ break; } } if(j == N){ return i; } } return -1; } char hacker_script(char c){ if(isupper(c)){ c = tolower(c); } char numbers[] = "0123456789"; char letters[] = "oizeasbtbq"; int i; for (i = 0; i < 10; i++){ if (c == numbers[i]){ c = letters[i]; return c; } } return c; } int main(){ printf("Zadaj hladanu surovinu:"); char key[LINESIZE]; memset(key,0,LINESIZE); char* r = fgets(key,LINESIZE,stdin); key[strlen(key)-1] = '\0'; int k = 0; for(k = 0; k < strlen(key); k++){ key[k] = hacker_script(key[k]); } printf("Zadaj jedalny listok:"); struct pizza jedalny_listok[100]; struct pizza pomocny[100]; memset(pomocny, 0, sizeof(struct pizza)*100); memset(jedalny_listok, 0,sizeof(struct pizza)*100); struct pizza item; int counter = 0; while(stdin,read_pizza(&item)){ strcpy(jedalny_listok[counter].name, item.name); jedalny_listok[counter].prize = item.prize; counter++; } int i, j, f; int i, j; for(i = 0; i < counter; i++){ for(j = 0; j < strlen(jedalny_listok[i].name); j++){ //change menu with help of hacher_script pomocny[i].name[j] = hacker_script(jedalny_listok[i].name[j]); } //check if there is key in the menu int result = search_string(pomocny[i].name, key); if(result != -1){ //if there is a key, print name and price printf("%s", jedalny_listok[i].name); printf("%.2f\n", jedalny_listok[i].prize); } } printf("Nacitanych %d poloziek.\n", counter); return 0; }