Problem with files

File does not work.Does not record information.Please help!
Compile program functions for:
-Enter of a keyboard and a file into an array (by adding) data to 30 girls in the competition "Miss World"
number, physical data, state and display the current contents of the array on the screen
-display output data for a girl by entered from the keyboard a number ( by request
a new report ).
-Displays data for the youngest girl in the competition and the number of girls under the age of 20 years.
Home-function main () menu selection functions and check the status of the data using the Global
variables or functions with transmission parameters, optional

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 #include <iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
#define N 30 

 FILE *fp;

 struct girl
{
char number[10];
int age;
int bust ;
char height[20]; 
char hip[20]; 
char waist[20]; 
char weight[20];
  }
gr[N];
int top=0;

int menu() 
{ 
 int ch; 
    cout<<"\n_______________MENU________________"; 
   cout<<"\n 1. Input number of girls"; 
   cout<<"\n 2. Display list of all girls"; 
   cout<<"\n 3. Display girls under 20"; 
   cout<<"\n 4. Girl largest bust "; 
   cout<<"\n 5. Search by number:"; 
   cout<<"\n 6. Exit"; 
   do 
   { 
           cout<<"\n Choice: "; 
           cin>>ch; 
   } 
   while(ch<1||ch>6); 
           return(ch); 
}


void load()
{
if ((fp=fopen("my.txt","rb"))==NULL)return;
if (fread(&top, sizeof top, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
if(fread(gr, sizeof gr, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
fclose(fp);
}
void save()
{
if ((fp=fopen("my.txt", "wb"))==NULL)
{cout<<"\n error"; exit(1);}
if(fwrite (&top,sizeof top, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
if(fwrite (gr, sizeof gr, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
fclose(fp);}
void disp(int n)
{
       cout<<"\n Number: "<<gr[n].number;
       cout<<"\n Age: "<<gr[n].age;
       cout<<"\n Waist: "<<gr[n].waist;
       cout<<"\n Hip: "<<gr[n].hip;
       cout<<"\n buist: "<<gr[n].bust;
       cout<<"\n weight:"<<gr[n].weight;
       cout<<"\n height:"<<gr[n].height;
}
void info()
{
int i;
cout<<"\n Spisyk: \n";
for(i=0; i<top; i++)
disp(i);
}

void enter()
{
   	int count=0,n, i, ost;
   	ost=N-top;
if(ost>0)
{cout<<"\n There is room for more"<<ost<<" contestants";
{
cout<<"\n New contestants:";cin>>count;}
while (count<0 || count>ost);
for (i=top; i<top+count; i++)
   {
   
       
       cout<<"\n Number: ";
       cin>>gr[i].number;
       cout<<"\n Age: ";
       cin>>gr[i].age;
       cout<<"\n hip: ";
       cin>>gr[i].hip;
       cout<<"\n waist: ";
       cin>>gr[i].waist;
       cout<<"\n bust: ";
       cin>>gr[i].bust;
       cout<<"\n weight:";
       cin>>gr[i].weight;
       cout<<"\n height:";
       cin>>gr[i].height;
   }
   top=i;
}
else cout<<"Error.";
}


void list() 
{
   int i;
   cout<<"\n List\n";
   for(i=0;i<top;i++)
   disp(i);
}
void teen() 
{ 
     int i; 
      cout<<"\n Girls under 20\n"; 
         for(i=0;i<top;i++) 
         {gr[i].age*=1; 
           if(gr[i].age<20) 
                   disp(i); 
         } 
} 
void showgirl(girl gr[N])

{
char t_number[10];

int i, found;


fflush(stdin);
cout<<"\n Search by number \n ";
cout<<"\n number \n";
cin>>t_number;;     
found=0;
for(i=0; i<top; i++){
if(!strcmp(t_number, gr[i].number)) {
disp(i);
found=1;

}
}
if(!found){
cout<<"\n Error. ";
}
}
void bust()
{int fb=0,pos=0,i;
    
	{
	string im;
		string ifn;
	int max=500;
	for(int r=0;r<fb;r++)
	{
	if(gr[r].bust<max)
	{
		max=gr[r].bust;
		im=gr[r].number;
	
		
	}
	}
	cout<<"\n Girl largest bust :"<< "\n "<<gr[i].number<<"\t"<<gr[i].age<<"\t"<<gr[i].waist<<"\t"<<gr[i].hip<<"\t"<<gr[i].bust<<"\t"<<gr[i].height<<"\t"<<gr[i].weight<<"\t"<<endl;
	for(i=0;i<pos;i++)
		for(int j=0;j<pos-i-1;j++)
			if(gr[j].bust>gr[j+1].bust)
			{
				girl c=gr[j];
				gr[j]=gr[j+1];
				gr[j+1]=c;
			}
			cout<<"\n "<<endl;
			for(int y=0;y<pos;y++)
				cout<<gr[y].number<<" "<<gr[y].bust<<endl;
}
			
}
 


int main()
{ int ch;
load();
do
{ ch=menu();
switch(ch)

           { 
           case 1: enter();break; 
           case 2: list();break; 
           case 3: teen();break; 
           case 4: showgirl(gr);break; 
           case 5: bust( );break;
  
}}
while (ch!=6);
}
Please, use C++ file handling.
http://www.cplusplus.com/doc/tutorial/files/

One question: you're building "porno.exe"? LoL :P
Topic archived. No new replies allowed.