Ok at the moment im just trying to load some data of a txt file into an array of structures and display it. But it isnt working proply. The data that im useing is:
8/2/2002
1 2 2 3
3 0 4 2
5 3 6 1
i have 7 of these.
Not sure if i have set up my structure proply to deal with. Do i need 1 integer for lines below the date or will i need 1 for each?
#include<iostream.h>
#include<fstream.h>
struct Tfixtures
{
char date[8];
int teams;
int scores;
int teams2;
int scores2;
};
void readfromfile(Tfixtures teamfixtures[], int size);
void showtoscreen(Tfixtures teamfixtures[], int size);
main()
{
const int MAX_NUM=7;
Tfixtures teamfixtures[MAX_NUM];
readfromfile(teamfixtures, MAX_NUM);
showtoscreen(teamfixtures, MAX_NUM);
return 0;
}
void readfromfile(Tfixtures teamfixtures[], int size)
{
int i;
ifstream fin;
fin.open("a:fixtures.txt");
for(i=0; i<size; i++)
{
fin>>teamfixtures[i].date>>ws;
fin>>teamfixtures[i].teams>>ws;
fin>>teamfixtures[i].scores>>ws;
fin>>teamfixtures[i].teams2>>ws;
fin>>teamfixtures[i].scores2>>ws;
}
fin.close();
}
void showtoscreen(Tfixtures teamfixtures[], int size)
{
int i;
for(i=0; i<size; i++)
{
cout<<teamfixtures[i].date<<endl;
cout<<teamfixtures[i].teams<<endl;
cout<<teamfixtures[i].scores<<endl;
cout<<teamfixtures[i].teams2<<endl;
cout<<teamfixtures[i].scores2<<endl;
}
}
Also is there some way i can output the file in the same format as it is in the txt, i cant seem to find anything on formatting.