Hi guys and girls, im currently struggling trying to work out all this array and file input stuff!
I have been going round in circles for the past few hours, reading books and googling everything i could, so now im hoping some of your intelligence will help me :)
Basically i have a text file, containing names each with 12 numbers underneath them:
Bob Smith
12 17 84 93 83 48 93 47 95 28 84 26
as an example :P
I need to take the first 6 numbers and put them into an array, and put the last 6 into a different array.
I'm struggling badly, here's what i have done:
#include <iostream.h>
#include <string>
#include <fstream>
using namespace std;
bool getInputFilename(char fname[])
{
ifstream fin;
cout << "Please enter the filename for input : ";
cin >> fname;
fin.open(fname, ios::nocreate);
if (!fin.is_open())
return false;
fin.close();
return true;
}
bool getOutputFilename(char fname[])
{
ofstream fout;
cout << "Please enter the filename for output : ";
cin >> fname;
fout.open(fname);
if (fout.fail())
return false;
fout.close();
return true;
}
int firstArray(int i, int array[6], int maxSize, int amountRead)
{
ifstream fin;
ofstream fout;
while(fin>>array[amountRead]&& amountRead < maxSize)
{
amountRead++;
}
for (i=0; i < 5; i++)
{
fout << array[i] << endl;
}
cin.get();
return 0;
}
void main()
{
ifstream fin;
ofstream fout;
char IFname[20], OFname[20];
while (!getInputFilename(IFname))
{
cout << "Invalid filename try again!\n\n";
}
while (!getOutputFilename(OFname))
{
cout << "Invalid filename try again!\n\n";
}
fout.open(OFname);
fin.open(IFname);
}
The attempt at an array does nothing and was the result of trial and error from all the reading i have been doing, but now im on the verge of throwing my monitor out of the window.
Any help very much appreciated, apologies for any spelling mistakes!