Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <stdio.h>
- # include <string.h>
- struct book{
- char title[30];
- char author[15];
- unsigned short int year;
- };
- int main()
- {
- struct book vector[5];
- int found = 0;
- char search[30];
- printf("Registration\n");
- for (int i = 0; i < sizeof(vector) / sizeof(struct book); i++){
- printf("\nBook %d\n\nTitle: ", i + 1);
- fgets(vector[i].title, 30, stdin);
- printf("\nAuthor: ");
- fgets(vector[i].author, 15, stdin);
- printf("\nYear: ");
- scanf("%d", &vector[i].year);
- fflush(stdin);
- }
- printf("Which title do you want to search?\n>>> ");
- fgets(search, 30, stdin);
- for (int i = 0; i < sizeof(vector) / sizeof(struct book); i++){
- if (strcmp(vector[i].title, search) == 0)
- printf("\n\n\nTitle:\t%s\nAuthor\t%s\nYear\t%d\n", vector[i].title, vector[i].author, vector[i].year);
- found += 1;
- }
- if (found == 0)
- printf("\n\nThere is no matches\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement