Posted: Fri Feb 06, 2004 5:58 pm Post subject: Loading .txt Files
I got this mostly from the help file, then I made a text file with the name "test.txt" and saved a few words in it, but when I press enter, and add some more words and run the program a strange box char appers, can I get rid of that?
code:
var fileNo : int
var fileName : string := "test.txt"
var inputVariable : string (117)
open : fileNo, fileName, read
read : fileNo, inputVariable
close : fileNo
put inputVariable
Sponsor Sponsor
Andy
Posted: Fri Feb 06, 2004 6:00 pm Post subject: (No subject)
y r u using read? thats for binary plus u have to save ur source in the same folder as ur txt file
Mazer
Posted: Fri Feb 06, 2004 6:01 pm Post subject: (No subject)
The problem is that you are trying to add text to a binary data file. You could have a program to write to the file in binary, but it would best not to edit the file in notepad or something.
Dan
Posted: Fri Feb 06, 2004 6:05 pm Post subject: (No subject)
i am gussing that whould repprestent a "\n" or a line break. i am not shure what u are doing but i think that it whould be eaer with put and get file i/o unless u are trying to do somting more comapliated then i think.
ex of get/put i/o for files from turing doc:
code:
var word : string
loop
get skip % Skip over any white space
exit when eof % Are there more characters?
get word % Input next token
put word % Output the token
end loop
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
TheXploder
Posted: Fri Feb 06, 2004 6:10 pm Post subject: (No subject)
the thing is that I just wanna load strings out of a text file...
I do have them saved in the dame folder... I just want to load it and read, almost like:
var words : array 1..10, 1..10 of string
I don't intend to change the array within the program at all... just load the info I need...
Mazer
Posted: Fri Feb 06, 2004 6:15 pm Post subject: (No subject)
OK, but it would still be easier to just use get, especially if that's all you'll be doing with it.
TheXploder
Posted: Fri Feb 06, 2004 6:20 pm Post subject: (No subject)
get, doesn't that make a person write something in? and I don't want that...
Andy
Posted: Fri Feb 06, 2004 6:21 pm Post subject: (No subject)
no... if u do get:fid,line u get from the txt file
Sponsor Sponsor
TheXploder
Posted: Fri Feb 06, 2004 6:26 pm Post subject: (No subject)
why doesn't this work?
code:
var fileNo : int
var fileName : string := "test.txt" % Name of file
var inputVariable : string (117)
open : fileNo, fileName, read
read : fileNo, inputVariable
var word : string
loop
get skip % Skip over any white space
exit when eof % Are there more characters?
get inputVariable % Input next token
end loop
close : fileNo
put inputVariable
Dan
Posted: Fri Feb 06, 2004 6:32 pm Post subject: (No subject)
Posted: Fri Feb 06, 2004 7:56 pm Post subject: (No subject)
whats wrong wit it?
TheXploder
Posted: Fri Feb 06, 2004 8:02 pm Post subject: (No subject)
I changed the code a bit, now it works, but exept for the fact that the top line is cut off somehow..:
code:
var map : array 1 .. 10, 1 .. 10 of int
var numbers : string := ""
var number : string := ""
var stremin, stremout : int %a var that is an int is needed to open a file
open : stremin, "test.txt", get %this will open a connection to get data
get : stremin, number
loop
exit when eof (stremin)
get : stremin, number
%numbers := numbers + number
put number
end loop
put numbers
Andy
Posted: Fri Feb 06, 2004 8:07 pm Post subject: (No subject)
cuz u got it before the loop
TheXploder
Posted: Fri Feb 06, 2004 8:09 pm Post subject: (No subject)