#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
usingnamespace std;
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;
fstream myFile("Sample.txt");
if(myFile.is_open())
{
while (! myFile.eof())
{
getline (myFile,line);
cout<<line<<endl;
}
cin.get();
myFile.close();
cin.get();
cout<<"\nPress Enter\n";
system("pause");
system("cls");
}
else cout<<"Unable to open file";
cin.get();
}
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;
}
i get an error when i try to search for a vacant seat..
How to go there?
Enter your name (only 1 word)
Then press 5
Then try to search for a seat..
If the seat is unavailable.. an error will exist
Next time use [code][/code] tags please
You are mixing C and C++, which language are you supposed to use? I'd suggest you using C++ streams instead of C handles
Doesn't have to be next time, you can edit your post right now. (see the edit button?) Just select the code and click the little hash button on the side.
can you help me? :(
He is:
I'd suggest you using C++ streams instead of C handles
After reading those, you should be able to replace all your C with C++, which is good for you, since it will be easier to work with. printf() can be replaced with cout and scanf() can be replaced with cin. When you switch from C file handles to C++ streams, you should also be able to change your char*'s to strings, again making it much easier to work with.