okay, ive been going okay on my assignment, but ive just run into a problem.
i need to read a file into my program, the data from the file is to be read, and then randomised to produce "match data" for some matches.
im not too sure on how to do this.
i have tested reading the file in and outputting it onto the program, but it seems to read the data vertically rather than line by line :S which causes even more of a problem.
my code.
// ************, Software Development
// Unit: 8, Programming and Concept
#include <iostream.h>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <fstream.h>
#include <stdlib.h>
#include <conio.h>
void main (void)
{
int date;
int datecheck = 01012007;
int datenum = 0;
int menuoption1 = 0;
int menuoption2 = 0;
int print1 = 0;
FILE *inputdata;
char temp[200];
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 252);
while (datenum <= 0)
{
cout << "+----------------------------------------------------+" << endl;
cout << "| Please Enter Date |" << endl;
cout << "| Format: ddmmyyyy |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> date;
cout << "+----------------------------------------------------+" << endl;
cout << "| Is Date Correct? |" << endl;
cout << "| No = 0, Yes = 1 |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> datenum;
}
cout << "+----------------------------------------------------+" << endl;
cout << "| Date Entered Successfully |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 46);
cout << "+----------------------------------------------------+" << endl;
cout << "| Welcome |" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Please Select An Option: |" << endl;
cout << "| |" << endl;
cout << "| 1. Match Schedule (default) |" << endl;
cout << "| 2. Input Match Results |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> menuoption1;
inputdata=fopen ("D:\\input data.txt", "rt");
if(!inputdata)
{
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 196);
cout << "+----------------------------------------------------+" << endl;
cout << "| Error Opening File, Closing Program |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
exit(1);
}
if (menuoption1 <= 1)
{
if (date == datecheck)
{
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 252);
cout << "+----------------------------------------------------+" << endl;
cout << "| Option 'Match Schedule' Selected |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 162);
cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| |" << endl;
cout << "| Access Granted |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 226);
cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| |" << endl;
cout << "| Todays Match Schedule is as follows: (tbs) |" << endl;
//while((temp=fge tc(inputdata))! =EOL)
while(fgets(tem p,200,inputdata ) !=NULL)
cout << temp;
cout << endl << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
//cout << "| File to be Printed? (tbs) |" << endl;
//cout << "| No = 0, Yes = 1 |" << endl;
//cout << "+----------------------------------------------------+" << endl;
//cout << " --> ";
//cin >> print1;
//if (print1 == 1)
//{
// ofstream print("lpt3");
// if(!print)
// {
// cout<<"could not open printer\n";
// exit(1);
// }
//}
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 46);
cout << "+----------------------------------------------------+" << endl;
cout << "| Welcome |" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Please Select An Option: |" << endl;
cout << "| |" << endl;
cout << "| 1. Input Match Results |" << endl;
cout << "| |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << " --> ";
cin >> menuoption2;
cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Match Result Input |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
}
else
{
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 252);
cout << "+----------------------------------------------------+" << endl;
cout << "| Option 'Match Schedule' Selected |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << endl << endl;
SetConsoleTextA ttribute(GetStd Handle(STD_OUTP UT_HANDLE), 196);
cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| |" << endl;
cout << "| Access Denied |" << endl;
cout << "+----------------------------------------------------+" << endl;
}
}
else
{ cout << "+----------------------------------------------------+" << endl;
cout << "| Salchester Primary School's |" << endl;
cout << "| Annual Games Competition |" << endl;
cout << "| Match Schedule |" << endl;
cout << "+----------------------------------------------------+" << endl;
cout << "| Match Result Input |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| test |" << endl;
}
fclose (inputdata);
}
of course, the code isnt quite complete anyways, but i need to get this reading and randomising sorted... the rest should fall into place.
maybe i should read the file into a seperate function?? i dont know... help lol