int main()
{
FILE *fp;
char *ptrname;
char *ptrseat;
int index;
char name[100];
char seat[20];
int selection;
ptrname = name;
ptrseat = seat;
char name1[100];
cout<<"Good Day Sir/Maam!\n";
cout<<"What is your First name?\n";
cin.getline(name,100);
cout<<"What do you want me to do?\n";
while (selection != 4)
{
cout<<"\n1. Check all user registered with their seats\n2. Check if my name is registered\n3. Register my name\n4. Exit\n";
cin>>selection;
switch (selection)
{
case 1:
cout<<"\nThe files from your text are: \n";
{
string line;
break;
case 2:
cout<<"Check taken seats";
cin.get();
break;
case 3:
{
cout<<"What is the name? \n";
cin>>name1;
cin.get();
cout<<"Where do you want to seat? (<digits 1-8><letters a-z> sample 4B)\n";
cin>>seat;
cin.get();
ofstream outfile;
outfile.open("sample.txt", ios::out|ios::app);
outfile<<name1<<endl;
outfile<<seat<<endl;
cout<<"\nPress any key to exit\n";
cin.get();
outfile.close();
}
break;
case 4:
cout<<"Bye";
cin.get();
break;
default:
cout<<"Invalid";
system("cls");
break;
}
}
return 0;
}
How to read every second line of my code in the textfile?
int main()
{
FILE *fp;
char *ptrname;
char *ptrseat;
int index;
char name[100];
char seat[20];
int selection;
ptrname = name;
ptrseat = seat;
char name1[100];
int lines_read = 0;
string line_of_file;
string nameline;
cout<<"Good Day Sir/Maam!\n";
cout<<"What is your First name?\n";
cin.getline(name,100);
system("cls");
cout<<"What do you want me to do?\n";
while (selection != 5)
{
cout<<"\n1. Check all user registered with their seats\n2. Check if my name is registered\n3. Register someone\n4. Check Occupied Seats\n5. Exit\n";
cin>>selection;
system("cls");
switch (selection)
{
case 1:
cout<<"\nThe files from your text are: \n";
{
string line;
cout << "Seat number -> "<< line_of_file<<endl;
cout << "So you are already registered "<<name<<"\n";
}
else
cout<<"You are not registered\n";
}
else
break;
}
system("pause");
system("cls");
break;
case 3:
{
cout<<"What is the name? \n";
cin>>name1;
cin.get();
cout<<"Welcome Davao";
cout<<"Where do you want to seat? (<digits 1-8><letters a-z> sample 4B)\n";
cin>>seat;
cin.get();
ofstream outfile;
outfile.open("sample.txt", ios::out|ios::app);
outfile<<name1<<endl;
outfile<<seat<<endl;
system("pause");
system("cls");
outfile.close();
}
break;
case 4:
{
cout<<"Here are the list of the occupied seats\n";
ifstream input_file("sample.txt");
while ( !input_file.eof() )
{
getline(input_file, line_of_file);
if(input_file)
{
++lines_read;
if(lines_read % 2 == 0 )
cout << "Seat number -> "<< line_of_file<<endl;
}
else break;
}
}
system("pause");
system("cls");
break;
case 5:
cout<<"Bye";
cin.get();
break;
default:
cout<<"Invalid";
system("cls");
break;
}
}
return 0;
}
The case : 2 will check if your name is already registered in the text file.. My problem is .. am i on the right track? .. hehe because there is a problem in searching a string in my text file.
Another problem sir is how i can manage to return the name of the passenger and his seat in CASE 2