Need Help - Read/Write for a file
Author |
Message |
RedRogueXIII
![](http://compsci.ca/v3/uploads/user_avatars/431887573481a2d69185a9.png)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
drumman4ever
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
RedRogueXIII
![](http://compsci.ca/v3/uploads/user_avatars/431887573481a2d69185a9.png)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|
|