11.10.2012, 17:55. Просмотров 427. Ответов 0
Задача: Ввести в файл INPUT.DAT инфу о людях. Затем найти по фамилии этого человека и скопировать все информацию в файл OUTPUT.DAT
Ошибка заключается в функции output_file_man_yo, программа копирует только строку с первой фамилией, а на последующие введенные не реагирует. Пожалуйста укажите на ошибку.
C++ |
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
| #include<iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
const int L=23;
struct information
{
char name[L];
char sername[L];
char address[L];
long number;
};
ofstream input_file("INPUT.DAT");
ofstream output_file("OUTPUT.DAT");
void output_file_man_yo (information x[], int n)
{
ifstream input_file("INPUT.DAT");
int i;
char find[1024];
for (i=0;i<n;i++)
{
cout<<"Enter the sername: ";
cin>>x[i].sername;
while (input_file.getline(find,1024))
{
if (strstr(find,x[i].sername)) output_file<<find<<endl;
}
}
}
void input_file_man_yo (information x[], int n)
{
int i;
for (i=0;i<n;i++)
{
clrscr();
cout<<"Registration persons: "<<endl;
cout<<" "<<"name:";
cin>>x[i].name;
input_file<<x[i].name<<": \n";
cout<<" "<<"sername:";
cin>>x[i].sername;
input_file<<x[i].sername<<" ";
cout<<" "<<"address:";
cin>>x[i].address;
input_file<<x[i].address<<" ";
cout<<" "<<"number:";
cin>>x[i].number;
input_file<<x[i].number<<endl;
clrscr();
}
}
void output_check (information x[], int n)
{
ifstream input_file("INPUT.DAT");
char line[128];
while (! input_file.eof())
{
input_file.getline(line,sizeof(line));
cout<<line<<endl;
}
}
void main ()
{
clrscr();
const int N=3;
information a[N];
int i,m,k;
cout<<"Enter number persons: ";
cin>>m;
input_file_man_yo (a,m);
cout<<"Structure test: "<<endl;
output_check (a,m);
met:
cout<<"Enter the number of persons cheked: ";
cin>>k;
if (k>m)
{
cout<<"Amount of the controlled persons is invalid!\n"<<m;
goto met;
}
clrscr();
output_file_man_yo (a,k);
clrscr();
cout<<"Information on your request was included in the file OUTPUT.DAT";
getch();
} |
|