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 3593 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
into Access. I want to avoid creating a separate "Spec" for each file
(there are over 180 files) and instead want to code my own dynamic
importing rules. So far it's been going fine, except for one item...
|
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 processing. I am having no luck at
all finding different routines written in C to read delimited files of any
kind. I have a few ideas of how I might go about this but I bet I'm
re-inventing the wheel and there already exists some efficient code out...
|
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 all the stats from that draw number
From http://www.developmentnow.com/g/36_2003_7_0_14_0/dotnet-languages-csharp.htm
|
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
server.
|
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 still get a
DBNull value... I'm not able to figure this one out, any help would be
appreciated.
Here's my code :
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & sPath & ";Extended...
| |
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 columns get read as
nulls). An example of an offending line is:
J" Invalid " ....
This is a text field that is between the two 'pipes' so I need it read
exactly as is.
I have reverted to schema files, trying everything I can to overcome this...
|
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 getting on more or less OK.
So far, I have managed to parse my tab-delimited .txt file properly into
an array, and then use this array to update the tags on a bunch of MP3
audio files. Nice.
|
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 Source=C:\dir1A\;Extended
Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn1x As New OleDb.OleDbConnection(ConStr)
Dim dax1 As New OleDbDataAdapter("Select * from testabc1x.txt", conn1x)
|
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.
Objective
My input file could be .txt or .dat or .csv
Any kind of delimited file with the following delimiters (',','/','|',';',':')
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |