Three things:
1. I believe the segmentation error came from the fact that you used a forward slash after "c:" instead of a backward slash, because it worked after I changed it to a backward slah.
2. I'm not sure if I'm doing something wrong, but the program didn't seem to want to open "c:\employees.dat", because I believe root directory used in a filestream is the folder that the file is in. Therefore, just put the .dat file in the same place as the program.
3. The program did not work for reading in the lines properly when I test-drove it. I added a .ignore function, which seems to have cleared it up.
Anyways, here's what it looks like; this should work:
Code:
int main()
{
ifstream data;
char string[80];
char s1[50][80];
data.open("employee.dat", ios::in);
if(!data)
{
cerr << "File cannot be opened!" << endl;
system("PAUSE");
}
for (int i = 0; !data.eof(); i++)
{
data.get(string,80,'\n');
strcpy(s1[i],string);
cout << s1[i] << endl;
data.ignore('\n', 10);
}
data.close();
system("PAUSE");
return 0;
}