include stdio include string define 10 struct car char number char mar

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <stdio.h>
#include <string.h>
#define N 10
struct car
{
char number[7];
char marka[20];
char surname[20];
char name[20];
char fname[20];
};
struct carcrash
{
char number[7];
};
struct masters
{
car elem[N];
int n;
masters ()
{
n = -1;
}
};
struct crash_masters
{
carcrash elem[N];
int n;
crash_masters ()
{
n = -1;
}
};
int main()
{
masters base;
crash_masters crash;
char buf[7], buf1[20];
int b, i, j;
FILE *fp;
fopen_s ( &fp, "avto_base.txt", "r" );
++base.n;
b = fscanf ( fp, "%s%s%s%s%s", base.elem[base.n].number, base.elem[base.n].marka, base.elem[base.n].surname, base.elem[base.n].name, base.elem[base.n].fname );
while ( b != -1 )
{
++base.n;
b = fscanf ( fp, "%s", buf );
if ( b != -1 )
{
for ( i = 0; i < base.n; ++i )
if ( strcmp( buf, base.elem[i].number ) < 0 )
{
for ( j = base.n; j > i; --j )
{
strcpy ( base.elem[j].number, base.elem[j-1].number );
strcpy ( base.elem[j].marka, base.elem[j-1].marka );
strcpy ( base.elem[j].surname, base.elem[j-1].surname );
strcpy ( base.elem[j].name, base.elem[j-1].name );
strcpy ( base.elem[j].fname, base.elem[j-1].fname );
}
break;
}
strcpy ( base.elem[i].number, buf );
b = fscanf ( fp, "%s%s%s%s", base.elem[i].marka, base.elem[i].surname, base.elem[i].name, base.elem[i].fname );
}
}
fclose (fp);
fopen_s ( &fp, "avto_crash_base.txt", "r" );
++crash.n;
b = fscanf ( fp, "%s%s", crash.elem[crash.n].number, buf1 );
while ( b != -1 )
{
++crash.n;
b = fscanf ( fp, "%s", buf );
if ( b != -1 )
{
for ( i = 0; i < crash.n; ++i )
if ( strcmp( buf, crash.elem[i].number ) < 0 )
{
for ( j = crash.n; j > i; --j )
{
strcpy ( crash.elem[j].number, crash.elem[j-1].number );
}
break;
}
strcpy ( crash.elem[i].number, buf );
b = fscanf ( fp, "%s", buf1 );
}
}
fclose (fp);
fopen_s ( &fp, "output.txt", "w" );
for ( i = 0; i < base.n; ++i )
fprintf_s ( fp, "%s %s %s %s %s \n", base.elem[i].number, base.elem[i].marka, base.elem[i].surname, base.elem[i].name, base.elem[i].fname );
for ( i = 0; i < crash.n; ++i )
fprintf_s ( fp, "%s \n", crash.elem[i].number );
fclose (fp);
fopen_s ( &fp, "avto.out.txt", "w" );
j = 0;
for ( i = 0; i < base.n; ++i )
for ( ; j < crash.n; ++j )
{
b = strcmp(base.elem[i].number, crash.elem[j].number);
if ( b == 0 )
fprintf_s ( fp, "%s %s %s \n", base.elem[i].surname, base.elem[i].name, base.elem[i].fname );
else
if ( b < 0 )
break;
}
fclose (fp);
}