I have a file that looks like this:
string string 0 1 34
string string 0 4 5 8 3 4
the 2nd number from the left shows how many numbers are going to follow it.
i.e. on the 2nd line, 4 has 5 8 3 4.
Does anybody know a way to read the file? I'm trying to read it and put the data in a two dimensional array. What i have is the following function: -
//---------------------------------------------------------
-
// This function takes student data file and reads the
-
// data in the two dimensional array for further processing
-
//---------------------------------------------------------
-
int stdLoadData(ifstream &ifile, string stdArray[][11]) {
-
string firstName, lastName, studentID, numOfCourses, course1, course2, course3, course4, course5, course6;
-
int j = 0;
-
string temp;
-
-
while (!ifile.eof()) {
-
getline(ifile,firstName,' ');
-
stdArray[j][stdFirstName] = firstName;
-
getline(ifile,lastName,' ');
-
stdArray[j][stdLastName] = lastName;
-
getline(ifile,studentID,' ' );
-
stdArray[j][stdStudentID] = studentID;
-
getline(ifile,numOfCourses, ' ');
-
stdArray[j][stdNumOfCourses] = numOfCourses;
-
-
if (numOfCourses == "1") {
-
getline(ifile,course1);
-
stdArray[j][stdCourse1] = course1;
-
} else if (numOfCourses == "2") {
-
getline(ifile,course1, ' ');
-
stdArray[j][stdCourse1] = course1;
-
getline(ifile,course2);
-
stdArray[j][stdCourse2] = course2;
-
} else if (numOfCourses == "3") {
-
getline(ifile,course1, ' ');
-
stdArray[j][stdCourse1] = course1;
-
getline(ifile,course2, ' ');
-
stdArray[j][stdCourse2] = course2;
-
getline(ifile,course3);
-
stdArray[j][stdCourse3] = course3;
-
} else if (numOfCourses == "4") {
-
getline(ifile,course1, ' ');
-
stdArray[j][stdCourse1] = course1;
-
getline(ifile,course2, ' ');
-
stdArray[j][stdCourse2] = course2;
-
getline(ifile,course3, ' ');
-
stdArray[j][stdCourse3] = course3;
-
getline(ifile,course4);
-
stdArray[j][stdCourse4] = course4;
-
} else if (numOfCourses == "5") {
-
getline(ifile,course1, ' ');
-
stdArray[j][stdCourse1] = course1;
-
getline(ifile,course2, ' ');
-
stdArray[j][stdCourse2] = course2;
-
getline(ifile,course3, ' ');
-
stdArray[j][stdCourse3] = course3;
-
getline(ifile,course4, ' ');
-
stdArray[j][stdCourse4] = course4;
-
getline(ifile,course5);
-
stdArray[j][stdCourse5] = course5;
-
} else if (numOfCourses == "6") {
-
getline(ifile,course1, ' ');
-
stdArray[j][stdCourse1] = course1;
-
getline(ifile,course2, ' ');
-
stdArray[j][stdCourse2] = course2;
-
getline(ifile,course3, ' ');
-
stdArray[j][stdCourse3] = course3;
-
getline(ifile,course4, ' ');
-
stdArray[j][stdCourse4] = course4;
-
getline(ifile,course5, ' ');
-
stdArray[j][stdCourse5] = course5;
-
getline(ifile,course6);
-
stdArray[j][stdCourse6] = course6;
-
}
-
j++;
-
}
-
return j;
-
}
-
which works unless the numOfCourses variable which is the 2nd number on every row, is 0. Then, since there is nothing after it, it doesn't take it as the end of line and read the 1st field from the next line.
Is there a way to fix that?
Thank you!
0 3579 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ben |
last post by:
Hi all -
I am having a bit of trouble and thought maybe someone in this group
could shed some light. Here's the skinny...
I am creating an automated process to import a bunch of text files...
|
by: John B. Lorenz |
last post by:
I'm attempting to write an input routine that reads from a comma delimited
file. I need to read in one record at a time, assign each field to a field
array and then continue with my normal...
|
by: Leonard Wright |
last post by:
I'm developing a lottery program and want read a text file that has
Draw date
Draw number
six lottery numbers
all in comma delimited text file
I want the user to select a draw number
to show...
|
by: svijay |
last post by:
hi
I have got a strange problem. May I know any solution for this.
Here is the detailed description about the problem
We have got a mainframe system and also production and development...
|
by: stephane8 |
last post by:
I'm able to open and read my .csv file. But when the character "-" is
in one of my fields (ex : 18802-002) I get a system.DBNull value ! Even
if I edit the file with notepad and put "18802-002" I...
| |
by: Masa Ito |
last post by:
I have pipe delimited (and comma/tab) files that I read with JET using a
schema file. Occasionally a field has multiple quotes (") inside a single
field - which chokes the line (the rest of the...
|
by: Wes Peters |
last post by:
Does anyone know of an article that deals with the subject of reading a
structured text file using VBA code in Access?
Thanks,
Wes
|
by: Clive Green |
last post by:
Hello peeps,
I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and
writing MP3 tags). I have been using PHP on the command line (Mac OS X
Unix shell, to be precise), and am...
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
'--this code works but only reads text into one column when contains multiple
cols
Dim ds1x As New DataSet
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data...
|
by: yesvee |
last post by:
Hello All,
I'm new for Python programming and I'm having some issues parsing a delimited text file. Any help, suggestions and advice is really appreciated. Thanks a lot in advance.
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |