I'm wiring a program where I have a file with city, state, population size laid out as follows;
24
El Paso, TX 577415
Indianapolis, IN 783612
Detroit, MI 925051
Fort Worth, TX 567516
Los Angeles, CA 3798981
Washington, DC 570898
etc... with 24 being the number of elements in the file.
I'm trying to write the data in the file into character arrays, char city[], char state[], int size[]
however I am having a problem with the getline command. I was originally using strings to store the data and had no problems, but I also need to use strcmp to alphabetize the data by city name and I was getting an error with strcmp not liking the strings.
int main()
{
const int LIMIT = 50;
string ifile,ofile;
char city[LIMIT], state[LIMIT],;
int size[LIMIT],num, menu;
ofstream fout;
ifstream fin;
cout << "Enter the input file name: ";
cin >> ifile;
fin.open(ifile.c_str());
if (fin.fail())
{
cout << "Open failed\n";
exit(1);
}
cout.setf(ios::left);
fout.setf(ios::left);
fin >> num;
fin.ignore(1000, '\n');
if (num > LIMIT)
{
cout << "Too many lines of data\n";
exit(1);
}
for (int i = 0; i< num; i++)
{
getline(fin,city[i],',');
fin >> state[i] >> size[i];
fin.ignore(1000, '\n');
}