Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Loading .txt Files
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheXploder




PostPosted: 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
Sponsor
sponsor
Andy




PostPosted: 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




PostPosted: 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




PostPosted: 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 Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
TheXploder




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Fri Feb 06, 2004 6:21 pm   Post subject: (No subject)

no... if u do get:fid,line u get from the txt file
TheXploder




PostPosted: 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




PostPosted: Fri Feb 06, 2004 6:32 pm   Post subject: (No subject)

b/c u are not using get right.....see this:

http://www.compsci.ca/v2/viewtopic.php?t=5
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
TheXploder




PostPosted: Fri Feb 06, 2004 6:50 pm   Post subject: (No subject)

ok, I tryed it and I still have difficulty:

code:

var temp : 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, temp

loop
    exit when eof (stremin)
    get : stremin, temp
end loop

put temp

close: stremout


my text file has this in it:

code:

1111111111
1000000001
1000000001
1000000001
1000000001
1000000001
1000000001
1000000001
1000000001
1111111111
Andy




PostPosted: Fri Feb 06, 2004 7:56 pm   Post subject: (No subject)

whats wrong wit it?
TheXploder




PostPosted: 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




PostPosted: Fri Feb 06, 2004 8:07 pm   Post subject: (No subject)

cuz u got it before the loop
TheXploder




PostPosted: Fri Feb 06, 2004 8:09 pm   Post subject: (No subject)

ohh, lol, thx
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 23 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: