include stdio include string define 10 define 20 struct type char numb

 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
#include <stdio.h>
#include <string.h>
#define N 10
#define M 20
struct type
{
char number[M];
char marka[M];
char name[M];
};
struct car
{
type elem[N];
int n;
car ()
{
n = -1;
}
};
int main()
{
car base;
char temp[M];
int b, i, j;
FILE *fp;
fopen_s ( &fp, "avto_base.txt", "r" );
++base.n;
b = fscanf ( fp, "%s%s%s", base.elem[base.n].number, base.elem[base.n].marka, base.elem[base.n].name);
while ( b!=-1 )
{
++base.n;
b = fscanf ( fp, "%s", temp );
if ( b != -1 )
{
for ( i = 0; i < base.n; ++i )
if ( strcmp( temp, 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].name, base.elem[j-1].name );
}
break;
}
strcpy ( base.elem[i].number, temp );
b = fscanf ( fp, "%s%s", base.elem[i].marka, base.elem[i].name);
}
}
fclose (fp);
/////////////////////////////////////////////////////////////////////////////
fopen_s ( &fp, "output.txt", "w" );
for ( i = 0; i < base.n; ++i )
fprintf_s ( fp, "%s %s %s \n", base.elem[i].number, base.elem[i].marka, base.elem[i].name );
fclose (fp);
/////////////////////////////////////////////////////////////////////////////
char key[10];
gets (key);
fopen_s ( &fp, "still_car.txt", "w" );
for ( i = 0; i < base.n; ++i )
{
b = strcmp(base.elem[i].marka, key);
if ( b == 0 ) fprintf_s ( fp, "%s %s \n", base.elem[i].number, base.elem[i].name );
}
fclose (fp);
}