|
|
|
Tamar Feldman
|
i have an assignment to read from a textfile line by line and then write them into another text file. another assignment is to read from a textfile line by line and whatever line contains the word 'you' is printed out on the screen.
can anyone help me?? Thank you! [Non-text portions of this message have been removed] |
|
chrs7777
|
Since this is an assignment you should be demonstrating how it is that you
are stuck - perhaps show some code that you have used to attempt to solve this problem. Regards Chris Saunders ----- Original Message ----- From: Tamar Feldman To: [hidden email] Sent: Sunday, October 25, 2009 4:09 PM Subject: [eiffel_software] (unknown) i have an assignment to read from a textfile line by line and then write them into another text file. another assignment is to read from a textfile line by line and whatever line contains the word 'you' is printed out on the screen. can anyone help me?? Thank you! [Non-text portions of this message have been removed] |
|||||||||||||||||||
|
rfo
|
In reply to this post
by Tamar Feldman
Hi Tamara!
There are plenty of folks on this list who can and will help you, but are you asking us to show you how to do your homework assignment? That, we won't do, but we will show you where to look in the Eiffel libraries to make it a pretty easy assignment. From your description, it sounds like you will need PLAIN_TEXT_FILE. Have a good look at that class. You must first create the file object of course (use 'make'). Files must be open before than can be read, and so you will have to open the first file for reading. The class provides all sorts of features, including one to read a line at a time. Have a look at that. There is one gotcha that every newbie hits. When a line of text is read, it is is stored in 'last_string'. Every time you read a line, that object gets new content. Be very sure to make a copy of the text you just read unless you want to see some strange behavior. If you follow the description of the assignment you gave us, you should have no problem, but if you keep references around in your code, you might run across this behavior. A new PLAIN_TEXT_FILE can be created easily enough. First create the object that represents it, then open the file for write (that will clobber whatever was in it before if you're reusing the same path). FILEs and console output are pretty similar in Eiffel because they have a common ancestor. The routine to write a string to a file is put_string, and the routine to write a string to standard output is also put_string (albeit from different classes). The file ones are there in the class text of PLAIN_TEXT_FILE. The console ones are in STD_FILES. To do the first part of your assignment, simply read until the end of file, writing each line out as you go (that's what your description says). For the second part, you simply have to see if the substring 'you' is in the last string you just read, and not write out the line if it's not there. The solution is embedded in that last sentence. Be sure to close the files when you're done with them. I've probably told you more than your instructor would like, but I imagine you're new to the language, and finding things can be a little daunting at first. Because STD_FILES is instantiated in ANY as 'io', and because every class automatically inherits ANY, you really only need to deal with two classes other than the root class of your application, and they are PLAIN_TEXT_FILE and STRING. The rest of the logic is on you. R ================================================== Roger F. Osmond > -------- Original Message -------- > Subject: [eiffel_software] (unknown) > From: Tamar Feldman <[hidden email]> > Date: Sun, October 25, 2009 4:09 pm > To: [hidden email] > i have an assignment to read from a textfile line by line and then write them into another text file. another assignment is to read from a textfile line by line and whatever line contains the word 'you' is printed out on the screen. > can anyone help me?? > Thank you! > > [Non-text portions of this message have been removed] |
|||||||||||||||||||
|
Tamar Feldman
|
Dear Roger, Thank you so much for the quick reply. i'll tell you the truth this is not exactly a homework assignment so the teacher doesnt really mind how much help i get, and there is no way he can help me because he doesnt know this language, so dont feel bad about helping me;) anyway ill tell you my problem, so far i havent even been able to open a simple textfile, this is what i have tried so far (it's just the make): make is -- Run application. local input : PLAIN_TEXT_FILE do input.make_open_read ("C:\hello.txt") end can you tell me what i am doing wrong and how i carry on from here? thank you! ________________________________ From: "[hidden email]" <[hidden email]> To: [hidden email] Sent: Sun, October 25, 2009 10:59:36 PM Subject: RE: [eiffel_software] (unknown) Hi Tamara! There are plenty of folks on this list who can and will help you, but are you asking us to show you how to do your homework assignment? That, we won't do, but we will show you where to look in the Eiffel libraries to make it a pretty easy assignment. From your description, it sounds like you will need PLAIN_TEXT_FILE. Have a good look at that class. You must first create the file object of course (use 'make'). Files must be open before than can be read, and so you will have to open the first file for reading. The class provides all sorts of features, including one to read a line at a time. Have a look at that. There is one gotcha that every newbie hits. When a line of text is read, it is is stored in 'last_string' . Every time you read a line, that object gets new content. Be very sure to make a copy of the text you just read unless you want to see some strange behavior. If you follow the description of the assignment you gave us, you should have no problem, but if you keep references around in your code, you might run across this behavior. A new PLAIN_TEXT_FILE can be created easily enough. First create the object that represents it, then open the file for write (that will clobber whatever was in it before if you're reusing the same path). FILEs and console output are pretty similar in Eiffel because they have a common ancestor. The routine to write a string to a file is put_string, and the routine to write a string to standard output is also put_string (albeit from different classes). The file ones are there in the class text of PLAIN_TEXT_FILE. The console ones are in STD_FILES. To do the first part of your assignment, simply read until the end of file, writing each line out as you go (that's what your description says). For the second part, you simply have to see if the substring 'you' is in the last string you just read, and not write out the line if it's not there. The solution is embedded in that last sentence. Be sure to close the files when you're done with them. I've probably told you more than your instructor would like, but I imagine you're new to the language, and finding things can be a little daunting at first. Because STD_FILES is instantiated in ANY as 'io', and because every class automatically inherits ANY, you really only need to deal with two classes other than the root class of your application, and they are PLAIN_TEXT_FILE and STRING. The rest of the logic is on you. R ============ ========= ========= ========= ========= == Roger F. Osmond > -------- Original Message -------- > Subject: [eiffel_software] (unknown) > From: Tamar Feldman <tamif88@yahoo. com> > Date: Sun, October 25, 2009 4:09 pm > To: eiffel_software@ yahoogroups. com > i have an assignment to read from a textfile line by line and then write them into another text file. another assignment is to read from a textfile line by line and whatever line contains the word 'you' is printed out on the screen. > can anyone help me?? > Thank you! > > [Non-text portions of this message have been removed] [Non-text portions of this message have been removed] |
|||||||||||||||||||
|
helmut.brandl
|
You have not yet created the `input' object. Since `make_open_read' is a
creation procedure, it is rather easy. Use create input.make_open_read (... instead of input.make_open_read (... Before you step from one beginners problem to the next, I would recommend that you read some tutorial on Eiffel (e.g. http://tecomp.sourceforge.net -> Eiffel programming language -> tutorial). Helmut Tamar Feldman wrote: > > Dear Roger, > Thank you so much for the quick reply. i'll tell you the truth this is not exactly a homework assignment so the teacher doesnt really mind how much help i get, and there is no way he can help me because he doesnt know this language, so dont feel bad about helping me;) > anyway ill tell you my problem, so far i havent even been able to open a simple textfile, this is what i have tried so far (it's just the make): > make is > -- Run application. > local > input : PLAIN_TEXT_FILE > do > input.make_open_read ("C:\hello.txt") > end > > can you tell me what i am doing wrong and how i carry on from here? > thank you! > > > > > ________________________________ > From: "[hidden email]" <[hidden email]> > To: [hidden email] > Sent: Sun, October 25, 2009 10:59:36 PM > Subject: RE: [eiffel_software] (unknown) > > > Hi Tamara! > > There are plenty of folks on this list who can and will help you, but > are you asking us to show you how to do your homework assignment? That, > we won't do, but we will show you where to look in the Eiffel libraries > to make it a pretty easy assignment. > >>From your description, it sounds like you will need PLAIN_TEXT_FILE. > Have a good look at that class. > > You must first create the file object of course (use 'make'). > Files must be open before than can be read, and so you will have to open > the first file for reading. > The class provides all sorts of features, including one to read a line > at a time. Have a look at that. > > There is one gotcha that every newbie hits. When a line of text is > read, it is is stored in 'last_string' . Every time you read a line, > that object gets new content. Be very sure to make a copy of the text > you just read unless you want to see some strange behavior. If you > follow the description of the assignment you gave us, you should have no > problem, but if you keep references around in your code, you might run > across this behavior. > > A new PLAIN_TEXT_FILE can be created easily enough. First create the > object that represents it, then open the file for write (that will > clobber whatever was in it before if you're reusing the same path). > FILEs and console output are pretty similar in Eiffel because they have > a common ancestor. The routine to write a string to a file is > put_string, and the routine to write a string to standard output is also > put_string (albeit from different classes). The file ones are there in > the class text of PLAIN_TEXT_FILE. The console ones are in STD_FILES. > > To do the first part of your assignment, simply read until the end of > file, writing each line out as you go (that's what your description > says). > For the second part, you simply have to see if the substring 'you' is in > the last string you just read, and not write out the line if it's not > there. The solution is embedded in that last sentence. > Be sure to close the files when you're done with them. > > I've probably told you more than your instructor would like, but I > imagine you're new to the language, and finding things can be a little > daunting at first. > > Because STD_FILES is instantiated in ANY as 'io', and because every > class automatically inherits ANY, you really only need to deal with two > classes other than the root class of your application, and they are > PLAIN_TEXT_FILE and STRING. > > The rest of the logic is on you. > > R > > ============ ========= ========= ========= ========= == > Roger F. Osmond > >> -------- Original Message -------- >> Subject: [eiffel_software] (unknown) >> From: Tamar Feldman <tamif88@yahoo. com> >> Date: Sun, October 25, 2009 4:09 pm >> To: eiffel_software@ yahoogroups. com >> i have an assignment to read from a textfile line by line and then write them into another text file. another assignment is to read from a textfile line by line and whatever line contains the word 'you' is printed out on the screen. >> can anyone help me?? >> Thank you! >> >> [Non-text portions of this message have been removed] > > > > > > > > > [Non-text portions of this message have been removed] > > > > ------------------------------------ > > Yahoo! Groups Links > > > |
|||||||||||||||||||
|
chrs7777
|
In reply to this post
by Tamar Feldman
If the code you quoted is the full extent of your code then how do you know
there is any problem so far? You could try this: print (input.is_open_read) This will print "True" if the file is open and "False" otherwise. I would recommend have a look at the source code for class PLAIN_TEXT_FILE and class FILE. This is quite a bit of reading but would be worthwhile in understanding the Eiffel approach. I was a little suspicious that you were not putting enough effort into accomplishing your assignment and that answering could do you more harm than good. Regards Chris Saunders ----- Original Message ----- From: Tamar Feldman To: [hidden email] Sent: Sunday, October 25, 2009 5:41 PM Subject: [eiffel_software] (unknown) Dear Roger, Thank you so much for the quick reply. i'll tell you the truth this is not exactly a homework assignment so the teacher doesnt really mind how much help i get, and there is no way he can help me because he doesnt know this language, so dont feel bad about helping me;) anyway ill tell you my problem, so far i havent even been able to open a simple textfile, this is what i have tried so far (it's just the make): make is -- Run application. local input : PLAIN_TEXT_FILE do input.make_open_read ("C:\hello.txt") end can you tell me what i am doing wrong and how i carry on from here? thank you! ________________________________ From: "[hidden email]" <[hidden email]> To: [hidden email] Sent: Sun, October 25, 2009 10:59:36 PM Subject: RE: [eiffel_software] (unknown) Hi Tamara! There are plenty of folks on this list who can and will help you, but are you asking us to show you how to do your homework assignment? That, we won't do, but we will show you where to look in the Eiffel libraries to make it a pretty easy assignment. From your description, it sounds like you will need PLAIN_TEXT_FILE. Have a good look at that class. You must first create the file object of course (use 'make'). Files must be open before than can be read, and so you will have to open the first file for reading. The class provides all sorts of features, including one to read a line at a time. Have a look at that. There is one gotcha that every newbie hits. When a line of text is read, it is is stored in 'last_string' . Every time you read a line, that object gets new content. Be very sure to make a copy of the text you just read unless you want to see some strange behavior. If you follow the description of the assignment you gave us, you should have no problem, but if you keep references around in your code, you might run across this behavior. A new PLAIN_TEXT_FILE can be created easily enough. First create the object that represents it, then open the file for write (that will clobber whatever was in it before if you're reusing the same path). FILEs and console output are pretty similar in Eiffel because they have a common ancestor. The routine to write a string to a file is put_string, and the routine to write a string to standard output is also put_string (albeit from different classes). The file ones are there in the class text of PLAIN_TEXT_FILE. The console ones are in STD_FILES. To do the first part of your assignment, simply read until the end of file, writing each line out as you go (that's what your description says). For the second part, you simply have to see if the substring 'you' is in the last string you just read, and not write out the line if it's not there. The solution is embedded in that last sentence. Be sure to close the files when you're done with them. I've probably told you more than your instructor would like, but I imagine you're new to the language, and finding things can be a little daunting at first. Because STD_FILES is instantiated in ANY as 'io', and because every class automatically inherits ANY, you really only need to deal with two classes other than the root class of your application, and they are PLAIN_TEXT_FILE and STRING. The rest of the logic is on you. R ============ ========= ========= ========= ========= == Roger F. Osmond > -------- Original Message -------- > Subject: [eiffel_software] (unknown) > From: Tamar Feldman <tamif88@yahoo. com> > Date: Sun, October 25, 2009 4:09 pm > To: eiffel_software@ yahoogroups. com > i have an assignment to read from a textfile line by line and then write > them into another text file. another assignment is to read from a textfile > line by line and whatever line contains the word 'you' is printed out on > the screen. > can anyone help me?? > Thank you! > > [Non-text portions of this message have been removed] [Non-text portions of this message have been removed] |
|||||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |