Hello, I am fairly inexperienced with coding and have been having trouble with a program I am trying to write. The problem is that when reading from a text file the program will only read some of the file not all of it. Any help would be greatly appreciated.
Here is the code:
int i = 0, cycle = 0, end = 0, year = 0, month = 0, count = 0;
CALL_DATA listd[100];
ifstream file ("list.txt");
if (file.is_open())
{
while (file.good())
{
file >> listd[i].list;
file >> listd[i].number;
file >> listd[i].lcmonth;
file >> listd[i].lcyear;
i++;
}
file.close();
}
for (year = 0;year < 200; year++)
{
for (month = 0; month < 13; month++)
{
for (i = 0; i < 100; i++)
{
if (listd[i].list[i] == '\0')
break;
if (listd[i].lcyear == year && listd[i].lcmonth == month)
{
if (count == 3)
{
cout << endl;
count = 0;
}
cout << listd[i].list;
count++;
if (listd[i].number != 0)
cout << " " << listd[i].number;
}
}
}
}
cout << endl;
return;
And here is the .txt file:
Alabama
0
0
0
Alaska
0
0
0
Arizona
0
0
0
Arkansas
0
0
0
California
0
0
0
Colorado
0
0
0
Connecticut
0
0
0
Delaware
0
0
0
Florida
0
0
0
Georgia
0
0
0
Hawaii
0
0
0
Idaho
0
0
0
Illinois
0
0
0
Indiana
0
0
0
Iowa
0
0
0
Kansas
0
0
0
Kentucky
0
0
0
Louisiana
0
0
0
Maine
0
0
0
Maryland
0
0
0
Massachusetts
0
0
0
Michigan
0
0
0
Minnesota
0
0
0
Mississippi
0
0
0
Missouri
0
0
0
Montana
0
0
0
Nebraska
0
0
0
Nevada
0
0
0
New Hampshire
0
0
0
New Jersey
0
0
0
New Mexico
0
0
0
New York
0
0
0
North Carolina
0
0
0
North Dakota
0
0
0
Ohio
0
0
0
Oklahoma
0
0
0
Oregon
0
0
0
Pennsylvania
0
0
0
Rhode Island
0
0
0
South Carolina
0
0
0
South Dakota
0
0
0
Tennessee
0
0
0
Texas
0
0
0
Utah
0
0
0
Vermont
0
0
0
Virginia
0
0
0
Washington
0
0
0
West Virginia
0
0
0
Wisconsin
0
0
0
Wyoming
0
0
0
Sorry for the length. What am I doing wrong?