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

Username:   Password: 
 RegisterRegister   
 Need Help - Read/Write for a file
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RedRogueXIII




PostPosted: Sat Nov 05, 2005 1:23 pm   Post subject: Need Help - Read/Write for a file

I need help on a porgram where it would would read a file, check for a certain character and then write everything but that character to a new file.
This is what i have so far. ( I dont know how to get the whole file's data)
code:
var fileold, filenew : int
var character : string := " "

open : fileold, "lol.txt", get,seek
open : filenew, "lol2.txt", put
 
for i : 1 .. 10000
get: fileold,
    if fileold not = character then
        put : filenew, filenew+fileold
    end if
end for

close : fileold
close : filenew


help would very much be appreciated.
Sponsor
Sponsor
Sponsor
sponsor
drumman4ever




PostPosted: Sat Nov 05, 2005 5:11 pm   Post subject: (No subject)

Well, when you get the line, you could put it to a temp variable, then check the temp if it is that character, if it isn't than write it out.
code:

get: fileold, temp
if temp not = character then
    put : filenew, temp
end if


Hope that helped you out.
Cervantes




PostPosted: Sat Nov 05, 2005 6:32 pm   Post subject: (No subject)

You don't get data character by character in Turing. You get it word by word or line by line.

Also, don't be using a for loop to get data from the file, unless you're certain how much data is in the file. Instead, use loops and eof:
code:

loop
     exit when eof (fileNo)
     get : fileNo, temp
     %process temp
end loop


You'll have to use some string manipulation to determine if the character is in the string. Either for loop through the string, or use index(). Check out the String Manipulation and Index tutorials in the Turing Tutorial section.

[edit] Oh wow. You are trying to put the sum of the integer values of your filenumber variables into your new file? No, those integer variables merely represent the file as an allocated object. They do not reflect the data inside the file.
RedRogueXIII




PostPosted: Sat Nov 05, 2005 10:16 pm   Post subject: (No subject)

honestly i just got frustrated.... its supposed to be transfering the first file's data while editing out all the spaces into a new file.
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 1  [ 4 Posts ]
Jump to:   


Style:  
Search: