473,473 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading a file with 2 variables

15 New Member
0 111111112 20 100
1 5555 4 A
1 5556 4 B

0 111111111 44 90
1 4444 4 A
1 4443 3 A

How am I supposed to differentiate lines of text like this? The lines starting with 0 are students followed by their student number and 2 other variables

The 1s are the courses the student has taken, the credit hours and their grades.

Obviously I do something with infile, but I don't understand how I'm supposed to differentiate between the two when it is reading. I would just like a kick start to gain a understanding.

I've done it when it was just a single variable like every line started with a first and last name so you just read through it.
Sep 6 '07 #1
3 1298
ilikepython
844 Recognized Expert Contributor
0 111111112 20 100
1 5555 4 A
1 5556 4 B

0 111111111 44 90
1 4444 4 A
1 4443 3 A

How am I supposed to differentiate lines of text like this? The lines starting with 0 are students followed by their student number and 2 other variables

The 1s are the courses the student has taken, the credit hours and their grades.

Obviously I do something with infile, but I don't understand how I'm supposed to differentiate between the two when it is reading. I would just like a kick start to gain a understanding.

I've done it when it was just a single variable like every line started with a first and last name so you just read through it.
Are you using C or C++? Maybe something like this:
Expand|Select|Wrap|Line Numbers
  1. if (line[0] == '0')
  2. {
  3.     ... process student ...
  4. }
  5. else if (line[1] == '1')
  6. {
  7.     ... process course ...
  8. }
  9.  
Sep 6 '07 #2
apedosmil8
15 New Member
Sorry, I'm using C++, I'll take a look at this.

Thanks.
Sep 6 '07 #3
ilikepython
844 Recognized Expert Contributor
Sorry, I'm using C++, I'll take a look at this.

Thanks.
It's pretty easy with C++. Just use getline on the file and use the code I showed you to process differently depending on the first char.
Sep 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
6
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
7
by: Santah | last post by:
hi I'm new to C++ and I'm currently working on Visual C++ 6.0 I'm trying to open a text file, and read some data from it part of the text file looks like this: --------
7
by: Daniel Moree | last post by:
I'm working on a program that must first establish if the file exists in the program directory then it must open if for reading, read each line and set the variables then the program goes on about...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
1
by: Andrea Gavana | last post by:
Hello NG, that may sound a silly question, but I didn't find anything really clear about the issue of reading unformatted big endian files with Python. What I was doing till now, was using...
4
waynetheengineer
by: waynetheengineer | last post by:
Hello everyone :) I am trying to write VB code for reading filenames and file property values in a specific directory. For example, I have a directory called C:/Bears and in that directory...
4
by: isaac2004 | last post by:
hello, what i am trying to do is set up a loop that grabs multiple variables from an input file. my question is, is there a built in function in the istream class that can grab multiple values on...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
5
by: imailz | last post by:
Hi all, since I'm forced to switch from Fortran to C I wonder if there is posibility in C: 1) to use implicit loops 2) to parse several variables which number is determined at runtime. ...
0
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...
0
Oralloy
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,...
0
agi2029
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.