Advertisement
Guest User

Files_12.1

a guest
Oct 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void main() {
  4. FILE* f1, * f2;
  5. f1 = fopen("f1.txt", "r");
  6. f2 = fopen("f2.txt", "w");
  7. int i = 0, j = 0, flag = 1, count = 0, p = 0, num = 0;
  8. char buf[50] = { '\0' }, c[1] = "", year[15] = { '\0' }, name[15] = { '\0' }, bufn[15] = { '\0' }, t[20] = { '\0' };
  9.  
  10. printf("Choose action: N, K.\n");
  11. scanf_s("%c", &c);
  12. if (c[0] == 'N') {
  13. printf("Enter the name: ");
  14. scanf_s("%s", &name);
  15. for (i = 0; !feof(f1); i++) {
  16. fgets(buf, 40, f1);
  17. for (j = 0; buf[j] != '-'; j++) {
  18. bufn[j] = buf[j];
  19. p = j + 2;
  20. }
  21. count = 0;
  22. if (strlen(name) == strlen(bufn)) {
  23. for (j = 0; j < strlen(name); j++)
  24. if (name[j] == bufn[j])
  25. count++;
  26. if (count == strlen(name)) {
  27. while (buf[p] != '-')
  28. p++;
  29. p++;
  30. for (j = p; j < strlen(buf); j++)
  31. t[j - p] = buf[j];
  32. printf("The number is ");
  33. puts(t);
  34. }
  35. }
  36. for (j = 0; j < strlen(buf); j++)
  37. buf[j] = '\0';
  38. for (j = 0; j < strlen(bufn); j++)
  39. bufn[j] = '\0';
  40. }
  41. }
  42. else
  43. if (c[0] == 'K') {
  44. printf("Enter the year: ");
  45. scanf_s("%s", &year);
  46. for (i = 0; !feof(f1); i++) {
  47. fgets(buf, 40, f1);
  48. while (buf[p] != '-')
  49. p++;
  50. p++;
  51. for (j = p; buf[j] != '-'; j++)
  52. t[j - p] = buf[j];
  53. if (atoi(t) >= atoi(year))
  54. count++;
  55. for (j = 0; j < strlen(buf); j++)
  56. buf[j] = '\0';
  57. for (j = 0; j < strlen(t); j++)
  58. t[j] = '\0';
  59. }
  60.  
  61. printf("There are %d telephone(-s).", count);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement