954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

reading in a txt file and storing various lines as different variables

hey guys, im fairly new to this so feel free to tell me if i need to supply more info.
basically i need to write code to read in a text file and store different values in different variables, so for example i would read in:

bob
1.1
maths
1.2
physics
1.3
chemistry
jim
2.1
dance
2.2
programming
2.3
gym


ect ect

this would bassically be for code to allocate students into classes so the names are the teachers and the subjects things they teach, with the numbers representing class codes. if all i can get to work is reading in and storing the values appropriatly that would buy me time (im pretty close to the deadline!).

thanks for your help, sorry if my question has been asked before but i didn't find a good answer on google.

bigdan

bigdan182
Newbie Poster
23 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

Create the class
Open the file
Read a line
Place it in the variable
continue.

Pretty basic stuff.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

waltP
sorry to be a pain but what is the code to itterate through the file doing different things with each line? is it any different from doing the same thing to every line?

bigdan182
Newbie Poster
23 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 
waltP sorry to be a pain but what is the code to itterate through the file doing different things with each line? is it any different from doing the same thing to every line?


No, it's no different.

Sorry, but what you are actually asking us to do is teach you how to do a loop, open a file, read a file, and create and store data into your class. This is ahelp forum, not a teach me forum. Your instructor should have taught you all the things I mentioned. Your job is to put them together to accomplish the project. Our job is to help you when you get stuck, not teach you from scratch.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Check out this link

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: