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

Username:   Password: 
 RegisterRegister   
 Searching a file
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ans4




PostPosted: Sat May 19, 2007 10:30 pm   Post subject: Searching a file

I want to search a file for the first word on each line but it only works for the first line so if I search for the first word on other lines, it won't work. Can anyone help me? Here's a part of the code I have.

code:
var x : string

get x

var counter : int := 0
var data : string
open : stream, "myText.txt", get

loop
    exit when eof (stream)
    counter += 1
    get : stream, data
    entry (counter).a := data
    get : stream, data
    entry (counter).b := data
    get : stream, data
    entry (counter).c := data
    get : stream, data
    entry (counter).d := data

end loop
close : stream

var search := x

for i : 1 .. counter

    if entry (i).name = search then
        locate (10, 30)
        put "A: ", entry (i).a
        locate (11, 30)
        put "B: ", entry (i).b
        locate (12, 30)
        put "C: ", entry (i).c
        locate (13, 30)
        put "D: ", entry (i).d
        exit
    end if

end for
Sponsor
Sponsor
Sponsor
sponsor
DIIST




PostPosted: Sun May 20, 2007 8:40 am   Post subject: Re: Searching a file

Here is an example, but it just displayed the first word of each line on the screen. Hope its helpful Wink .
Turing:

var stream : int
var variable : string := ""
open : stream, "file.txt", get


loop
    exit when eof (stream)
    get : stream, variable       %Gets the First Word
    put variable
    get : stream, variable :*    %reads the rest of the line
end loop
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  [ 2 Posts ]
Jump to:   


Style:  
Search: