Не получается найти ошибку в функции поиска
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include "PrintCyr.h"
#include <time.h>
#include <ctype.h>
#include<cstdio>
using namespace std;
int NumOfFunction;
typedef struct vecPoezd *po;
typedef struct vecPoezd
{
int n_p;
string p_o;
string p_n;
time_t v_o;
po sled;
vecPoezd ()
{
sled=NULL;
}
}Leader;
class Poezd
{
public:
void vvod(po &tmp, int &, string &, string &, time_t &);
void vivod(po viv);
void poisk(char a[5]);
void poiskPoStancii(char a[5]);
};
void Poezd::vvod(po &tmp, int &n_p, string &p_o, string &p_n, time_t &v_o)
{
if(tmp==NULL)
{
tmp=new vecPoezd();
(*tmp).n_p=n_p;
(*tmp).p_o=p_o;
(*tmp).p_n=p_n;
(*tmp).v_o=v_o;
}
else vvod((*tmp).sled, n_p, p_o, p_n, v_o);
}
void Poezd::vivod(po viv)
{
if(viv!=NULL)
{
cout<<(*viv).n_p<<" "<<(*viv).p_o<<" "<<(*viv).p_n<<" "<<(*viv).v_o<<endl;;
vivod((*viv).sled);
}
}
void Poezd::poisk(char a[5])
{
Poezd *tmp2;
tmp2=new Poezd;
tmp2=sled;
int fl=1;
while(fl==1)-
{ int j=0;
while(j<5)
{
if(tmp2->n_p[j]!=a[j])
j=7;
if(j==4)
{
if(tmp2->n_p[j]==a[j])
{
cout<<tmp2->p_n;
cout<<"-";
cout<<"vremya otpravlenia";
cout<<tmp2->v_o;
cout<<tmp2->p_n;
cout<<"\n";
}
}
j++;
}
tmp2=tmp2->next;
}
}
void main()
{
Poezd a;
po tmp;
tmp=NULL;
while(NumOfFunction!=6)
{
cout<<"Menu:"<<endl;
cout<<"1: Nachalnoe formirovanie svedenii.Nazmite '1'"<<endl;
cout<<"2: Svedeniya is faila. Nazmite '2'"<<endl;
cout<<"3: Vivod svedenii po vsem poezdam.Nazmite '3'"<<endl;
cout<<"4: Po poezdu s zaproshennim nomerom.Nazmite '4'"<<endl;
cout<<"5: Po tem poezdam kot sleduyut do zaproshennoi stancii.Nazmite '5'"<<endl;
cout<<"6: Zavershenie raboty progi.Nazmite'6'"<<endl;
cout<<"Vash vibor: ";
cin>>NumOfFunction;
cout <<endl;
if ((NumOfFunction<1)||(NumOfFunction>6))
{
cout<<"Vi vveli nekorrektnuyu komandu!"<<endl;
NumOfFunction=0;
}
switch (NumOfFunction)
{
case 1:
{
int bred=0;
ofstream file;
file.open("bd",ios::app );
if(!file){
cerr<<"File otkrit nevozmogno\n";
}
while(bred!=1)
{
int n_p;
string p_o;
string p_n;
time_t v_o;
cout <<"Vvedite nomer poezda\n";
cin >>n_p;
if (n_p==0) break;
cout <<"vvedite punkt otpravleniya\n";
cin>>p_o;
cout <<"vvedite punkt nazna4eniya\n";
cin>>p_n;
cout<<"vvedite vremya otpravleniya\n";
cin>>v_o;
file<<n_p<<" "<<p_o<<" "<<p_n<<" "<<v_o<<endl;
a.vvod(tmp, n_p, p_o, p_n, v_o);
}
file.close();
break;
}
case 2:
{
fstream file;
file.open("bd",ios::in);
if (!file)
{
cerr <<"File otkrit nevozmogno!"<<endl;
break;
}
int n_p;
while (file>>n_p)
{
string p_o;
string p_n;
time_t v_o;
file>>p_o;
file>>p_n;
file>>v_o;
a.vvod(tmp, n_p, p_o, p_n, v_o);
}
file.close();
break;
}
case 3:
{
a.vivod(tmp);
break;
}
case 4:
{
a.poisk(tmp2);
break;
}
case 6:
{
exit(0);
}
} //????? switch
} //while
} //main