No, I double-checked that phone.h was only in there one time. I tried creating a new project and copying the header code into a new header and the include statements plus a blank main function into a new .cpp file and still got the same errors. Here's the rest of the code anyways (it's not quite done, it doesn't do what it's supposed to do, but at least it should compile so I can fix the errors!):
Code:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <string>
#include "phone.h"
using namespace std;
int modFlag=FALSE;
phoneNumber phoneList[LISTMAX];
int main(int argc, char*argv[])
{
//pass the phonelist file name in on the command line
char c;
ifstream infile;
if (argc<2)
{
cout << "You must open this file from the command prompt." << endl;
cout << "Type the .exe file name and the name of the .dat file";
cout << "after it, separated by spaces, and press enter." << endl;
}
else
{
infile.open(argv[1], ios::in | ios::binary);
if (infile)
infile.read((char*)phoneList, LISTMAX*sizeof(phoneNumber));
infile.close();
printList(phoneList, LISTMAX);
cout << "Enter the first letter of your choice and press enter: " << endl;
menu();
cin >> c;
while (tolower(c)!='q')
{
switch (c)
{
case 'e':
editList(phoneList, LISTMAX);
modFlag=TRUE;
break;
case 'l':
printList(phoneList, LISTMAX);
break;
case 's':
if (!saveList(phoneList, sizeof(phoneNumber), LISTMAX, argv[1]))
cout << "Error2." << endl;
else
modFlag=FALSE;
break;
}
cout << "Enter the first letter of your choice and press enter: " << endl;
menu();
cin >> c;
}
if (modFlag==TRUE)
{
cout << "Please save the file." << endl;
cin >> c;
if (tolower(c)=='y')
{
if (!saveList(phoneList, sizeof(phoneNumber), LISTMAX, argv[1]))
cout << "Error3." << endl;
else
modFlag=FALSE;
}
}
}
return 0;
}
void menu()
{
cout << " (E)dit (L)ist (S)ave (Q)uit " << endl;
}
void editList(phoneNumber L[], int n)
{
int i;
char ch;
cout << "Enter the index number (1 through 20) of a phone list item." << endl;
cin >> i;
cin.ignore(10, '\n'); //strips whitespace to prevent problems with getline()
i--; //adjust to array index(0 to n-1)
if (i<=n)
{
cout << "Enter the name:" << endl;
cin.getline(L[n].name, NAMEMAX);
cout << "Enter the phone number: [ex. (123) 456-7890]" << endl;
//uses ch variable to read and ignore the (, ), and - characters
cin >> ch;
cin >> L[n].areaCode;
cin >> ch;
cin >> L[n].exchange;
cin >> ch;
cin >> L[n].number;
}
}
void printList(phoneNumber L[], int n)
{
int i;
for (i=1; i<=n; i++)
printMember(L, i);
}
void printMember(phoneNumber L[], int i)
{
cout << setw(3) << i << ". " << L[i].name;
cout << setw(30) << "(" << L[i].areaCode << ") " << L[i].exchange << "-" << L[i].number << endl;
}
int saveList(phoneNumber L[], int recSize, int arraySize, char* fname)
{
int rtrn;
ofstream outfile;
outfile.open(fname, ios::out|ios::trunc|ios::binary);
if (!outfile)
rtrn=FALSE;
else if (!outfile.write((char*)L, recSize*arraySize))
{
outfile.close();
rtrn=FALSE;
}
else
{
outfile.close();
rtrn=TRUE;
}
return rtrn;
}
Arrgh. So frustrating.