Looking at what you had at the link you provided ...
if the data in your file is all pre-validated ...

i.e. ...

1) if the C strings are all less than 30 char's long (just one word, no spaces in 'word')

2) id#'s all fit into an unsigned short

3) if the data in the file is perfectly regular with idNuum on 1st line, name on next line, a valid float on 3rd line, (or all data has just whitespace between each data field)

then you easily could hande like this:

struct Customer 
    unsigned short int IDnum;
    char name[30];
    float salesCustomer; 
} ;

// ...

int fillAryFromFile( const char* fname, char Customer ary[], int max_size )
    int size = 0;
    ifstream fin( fname );
    if( fin )
            size < max_size &&
            fin >> ary[size].IDnum &&
            fin >> ary[size].name &&
            fin >> ary[size].salesCustomer
            if( size == max_ size )
                cout << "You have reached max size.\n";
        return size;
    // else ... if reach here ...
    cout << "There was a problem opening file.\n";
    return -1; // flag value for file open error

Edited 2 Years Ago by David W

I am not supposed to use pointers :( in class

I am dooing like this but read only one line with error:

int setRecord(char masterFile[15], master masterRecord[]){
    int i=0;
    char id[10], name[17], sale[8];
    ifstream read;

        cout<<"Open Fail";

            read.get(id, '\t');
            read.get(name, '\t');




    return i;

Edited 2 Years Ago by salafiyya1

Just change the top line in the example ... to:

int fillAryFromFile( const char fname[], char Customer ary[], int max_size )
This article has been dead for over six months. Start a new discussion instead.