C++ homework help - please!

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
Can i do this? it does not seem to work....


class EmployData
{
private:

getData();
getFile();
//closeFile(); //not created yet
ifstream in_file; //function header?
char Data[546]; // create an array for data from file
public: //temporary so this compiles
void showData(void);
};

EmployData::getFile()
{
in_file.open("SEmploy.txt"
cout << &quot;in getFile&quot; << endl;

if (in_file.fail())
{
cout << &quot;the file failed to OPEN please check the file
and try again. &quot; << endl;

exit(1);
}
}


EmployData::getData()
{
//ifstream SEmploy.txt;

//char Data[546];

in_file.get(Data, 546);


char strNum[6], fstName[50], lstName[50];
const char toksep[] = &quot; \n&quot;;
int nNum;
char *ptr;

cout << &quot;in getData&quot; << endl;

ptr = strtok(Data, toksep);
strcpy(strNum, ptr);
nNum = atoi(strNum);
ptr = strtok(NULL, toksep);
strcpy(lstName, toksep);
ptr = strtok(NULL, toksep);
strcpy(fstName, toksep);
}

void EmployData::showData(void)
{
cout << Data[2] << endl;

}



I'm really only concerned as to why I can't seem to get the file open...
 

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
ok, I figued it out... kinda of I'm having some trouble with that string function now...
 

MC

Platinum Member
Feb 23, 2000
2,747
0
0
are you actually getting any syntex error?

where is your main function?
 

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
Ming:
Here is my main, its in a *.cpp file.

#include <iomanip.h>
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include &quot;proj2.h&quot;

void main()
{
EmployData a;
a.getFile();
a.getData();
a.showData();
cout << &quot;hello&quot; << endl;
getch();

//return 0;
}


it compiles and even runs but the problem lies in this section of code:

EmployData::getData()
{
//ifstream SEmploy.txt;

//char Data[546];

in_file.get(Data, 546);


char strNum[6], fstName[50], lstName[50];
const char toksep[] = &quot; \n&quot;;
int nNum;
char *ptr;

cout << &quot;in getData&quot; << endl;

ptr = strtok(Data, toksep);
strcpy(strNum, ptr);
nNum = atoi(strNum);
ptr = strtok(NULL, toksep);
strcpy(lstName, toksep);
ptr = strtok(NULL, toksep);
strcpy(fstName, toksep);
}

------

strNum and fstName, lstName arrays are not getting populated... and so the rest doesn't work...
 

MC

Platinum Member
Feb 23, 2000
2,747
0
0
well, your code seems ok to me but

this ---> in_file.get(Data, 546);

confuses me!

what is the 546 doing there??
 

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
well, I toughtit would read 546 characters from the file that was opened to store in the Data array... no?

I then wanted to pull from the Data array into the str arrays
 

MC

Platinum Member
Feb 23, 2000
2,747
0
0
no......

the .get() will only read ONE character at a time!

 

MC

Platinum Member
Feb 23, 2000
2,747
0
0
depends of what kind of file do you have assuming you know that.

If it's just a line of data....then use fin.getline(Data,546) this will read until the &quot;/n&quot; or up to 546.

you can also use >> to read the data but it will SKIP the SPACE and LINE BREAK
 

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
Actually it reads the whole line, BUT only that line...

which looks like this BTW, 57915 Calahan Harry
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |