Guest User

Untitled

a guest
Apr 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct note
  6. {
  7. char name[30];
  8. int bday[3];
  9. long tele;
  10. };
  11.  
  12. int main()
  13. {
  14. FILE *f1;
  15. struct note blocknote[8];
  16. int i, check=0;
  17. char buff[3];
  18. long num;
  19.  
  20. if(f1 = fopen("f1.txt", "r"))
  21. {
  22. printf("File is open.\n");
  23. for(i=0; i<8; i++)
  24. {
  25. printf("======================================\n");
  26. fgets(blocknote[i].name, 30, f1);
  27. printf("Name: ");
  28. puts(blocknote[i].name);
  29.  
  30. fscanf(f1, "%d %d %d", &blocknote[i].bday[0], &blocknote[i].bday[1], &blocknote[i].bday[2]);
  31. printf("Birthday: %d.%d.%d ", blocknote[i].bday[0], blocknote[i].bday[1], blocknote[i].bday[2]);
  32.  
  33. fscanf(f1, "%li", &blocknote[i].tele);
  34. printf("\nTelenumber: +7(961)_%li\n", blocknote[i].tele);
  35. fgets(buff, 2, f1);
  36. printf("======================================\n");
  37. }
  38. }
  39.  
  40. printf("All persons: \n");
  41. for(i=0; i<8; i++)
  42. {
  43. printf("%d\n", blocknote[i].tele);
  44. }
  45.  
  46. printf("Find person (throghout num): ");
  47. scanf("%li", &num);
  48.  
  49. printf("======================================\n");
  50. for(i=0; i<8; i++)
  51. {
  52. if(num == blocknote[i].tele)
  53. {
  54. printf("Name: ");
  55. puts(blocknote[i].name);
  56. printf("Birthday: %d.%d.%d ", blocknote[i].bday[0], blocknote[i].bday[1], blocknote[i].bday[2]);
  57. printf("\n");
  58. check = 1;
  59. }
  60. }
  61. if(check==0)
  62. {
  63. printf("Not exist.\n");
  64. }
  65. printf("======================================\n");
  66.  
  67. return 0;
  68. }
Add Comment
Please, Sign In to add comment