Added read pizza, fixed main
This commit is contained in:
parent
eddecb5fff
commit
e5ade5c273
@ -1,4 +1,5 @@
|
||||
#define LINE_SIZE 100
|
||||
#define POCET_JEDAL 3
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
@ -7,6 +8,13 @@ struct pizza
|
||||
{ float prize;
|
||||
char name[LINE_SIZE];
|
||||
};
|
||||
struct pizza jedalny_listok[POCET_JEDAL];
|
||||
struct pizza *prva = jedalny_listok;
|
||||
struct pizza *druha = jedalny_listok + 1;
|
||||
struct pizza *tretia = &jedalny_listok[2];
|
||||
|
||||
|
||||
|
||||
|
||||
char hacker_script(char c) {
|
||||
|
||||
@ -27,16 +35,31 @@ char hacker_script(char c) {
|
||||
|
||||
return c;
|
||||
}
|
||||
//int read_pizza(struct pizza* item){
|
||||
//char line[LINE_SIZE];
|
||||
//char line2[LINE_SIZE];
|
||||
// memset(line,0,LINE_SIZE);
|
||||
// memset(line2,0,LINE_SIZE);
|
||||
//fgets(line, sizeof(line), item->name);
|
||||
//float value = strtof(line2, item->prize);
|
||||
// printf("%s ", line2);
|
||||
int read_pizza(struct pizza *item) {
|
||||
char line[LINE_SIZE];
|
||||
char line2[LINE_SIZE];
|
||||
|
||||
if (!fgets(line, sizeof(line), stdin))
|
||||
return 0;
|
||||
if (strlen(line) == 0)
|
||||
return 0;
|
||||
|
||||
if (!fgets(line2, sizeof(line2), stdin))
|
||||
return 0;
|
||||
|
||||
|
||||
char *endptr;
|
||||
float value = strtof(line2, &endptr);
|
||||
|
||||
if (value == 0.0F)
|
||||
return 0;
|
||||
|
||||
strcpy(item->name, line);
|
||||
item->prize = value;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
int search_string(const char* heap, const char* needle) {
|
||||
|
||||
@ -67,7 +90,24 @@ int search_string(const char* heap, const char* needle) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int res = search_string("8rynd20va P1zza", "pizza");
|
||||
printf("%d", res);
|
||||
}
|
||||
int main() {
|
||||
printf("Zadaj hladanu surovinu:\n");
|
||||
char search[LINE_SIZE];
|
||||
if (!fgets(search, sizeof(search), stdin)) {
|
||||
return 1;}
|
||||
search[strcspn(search, "\n")] = '\0';
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
|
||||
int loaded = 0;
|
||||
while (loaded < POCET_JEDAL && read_pizza(&jedalny_listok[loaded])) {
|
||||
loaded++;
|
||||
}
|
||||
|
||||
for(int i = 0; i<loaded; i++){
|
||||
if(search_string(jedalny_listok[i].name , search) != -1){
|
||||
printf("%s%.2f\n", jedalny_listok[i].name, jedalny_listok[i].prize);
|
||||
}
|
||||
}
|
||||
printf("Nacitanych %d poloziek.\n", loaded);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user