Advertisement
pedrolemoz

Untitled

Nov 30th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. # include <stdio.h>
  2. # include <string.h>
  3.  
  4. struct book{
  5. char title[30];
  6. char author[15];
  7. unsigned short int year;
  8. };
  9.  
  10. int main()
  11. {
  12. struct book vector[5];
  13. int found = 0;
  14. char search[30];
  15.  
  16. printf("Registration\n");
  17. for (int i = 0; i < sizeof(vector) / sizeof(struct book); i++){
  18. printf("\nBook %d\n\nTitle: ", i + 1);
  19. fgets(vector[i].title, 30, stdin);
  20.  
  21. printf("\nAuthor: ");
  22. fgets(vector[i].author, 15, stdin);
  23.  
  24. printf("\nYear: ");
  25. scanf("%d", &vector[i].year);
  26. fflush(stdin);
  27. }
  28.  
  29. printf("Which title do you want to search?\n>>> ");
  30. fgets(search, 30, stdin);
  31.  
  32. for (int i = 0; i < sizeof(vector) / sizeof(struct book); i++){
  33. if (strcmp(vector[i].title, search) == 0)
  34. printf("\n\n\nTitle:\t%s\nAuthor\t%s\nYear\t%d\n", vector[i].title, vector[i].author, vector[i].year);
  35. found += 1;
  36. }
  37.  
  38. if (found == 0)
  39. printf("\n\nThere is no matches\n");
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement