Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void main() {
- FILE* f1, * f2;
- f1 = fopen("f1.txt", "r");
- f2 = fopen("f2.txt", "w");
- int i = 0, j = 0, flag = 1, count = 0, p = 0, num = 0;
- char buf[50] = { '\0' }, c[1] = "", year[15] = { '\0' }, name[15] = { '\0' }, bufn[15] = { '\0' }, t[20] = { '\0' };
- printf("Choose action: N, K.\n");
- scanf_s("%c", &c);
- if (c[0] == 'N') {
- printf("Enter the name: ");
- scanf_s("%s", &name);
- for (i = 0; !feof(f1); i++) {
- fgets(buf, 40, f1);
- for (j = 0; buf[j] != '-'; j++) {
- bufn[j] = buf[j];
- p = j + 2;
- }
- count = 0;
- if (strlen(name) == strlen(bufn)) {
- for (j = 0; j < strlen(name); j++)
- if (name[j] == bufn[j])
- count++;
- if (count == strlen(name)) {
- while (buf[p] != '-')
- p++;
- p++;
- for (j = p; j < strlen(buf); j++)
- t[j - p] = buf[j];
- printf("The number is ");
- puts(t);
- }
- }
- for (j = 0; j < strlen(buf); j++)
- buf[j] = '\0';
- for (j = 0; j < strlen(bufn); j++)
- bufn[j] = '\0';
- }
- }
- else
- if (c[0] == 'K') {
- printf("Enter the year: ");
- scanf_s("%s", &year);
- for (i = 0; !feof(f1); i++) {
- fgets(buf, 40, f1);
- while (buf[p] != '-')
- p++;
- p++;
- for (j = p; buf[j] != '-'; j++)
- t[j - p] = buf[j];
- if (atoi(t) >= atoi(year))
- count++;
- for (j = 0; j < strlen(buf); j++)
- buf[j] = '\0';
- for (j = 0; j < strlen(t); j++)
- t[j] = '\0';
- }
- printf("There are %d telephone(-s).", count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement