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

Username:   Password: 
 RegisterRegister   
 Changing a Text File Program to a Binary File Program (searching)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
Tubby_Kat




PostPosted: Sun May 17, 2009 9:44 am   Post subject: Changing a Text File Program to a Binary File Program (searching)

What is it you are trying to achieve?
I'm trying to get the program to search for contacts that was formally a text file program to a binary file program.


What is the problem you are having?
It won't search for names or anything when it's a binary file

Describe what you have tried to solve this problem
Get it to search


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Not the real program, but an example.

Turing:


procedure putHeader ()
   
    put "Name" : 15 ..
    put "Student ID" : 10 ..
    put "     Grade" : 10
    for i : 1 .. 35
        put "=" ..
    end for
    put ""
end putHeader

function searchString (lookString, inString : string) : boolean
    var lookLength, inLength : int
    var numCompares : int
    var found : boolean := false
    var subString : string

   
    lookLength := length (lookString)
    inLength := length (inString)

        if lookLength <= inLength then
        numCompares := inLength - lookLength
        for i : 0 .. numCompares
           
            subString := inString ((1 + i) .. (lookLength + i))
            if subString = lookString then
                found := true
            end if
        end for
    end if
    result found
end searchString

type studentData :
    record
        name : string
        id : int
        grade : real
    end record

var student : studentData
var fileid : int
var searchName : string
var searchFound : boolean

open : fileid, "student_list.bin", write, mod

for x : 1 .. 4
    put "Enter stuff:"
    get student.name
    put "Enter stuff:"
    get student.id
    put "Enter stuff:"
    get student.grade
end for
close : fileid


open : fileid, "student_list.bin", read, mod, seek

put "Search for name (or part of name)? " ..
get searchName

searchFound := false     

putHeader ()

loop
    exit when eof (fileid)
    read : fileid, student.name
    read : fileid, student.id
    read : fileid, student.grade

   
    if searchString (searchName, student.name) then
        searchFound := true
       
        put student.name : 15 ..
        put student.id : 10 ..
        put student.grade : 10 : 1
    end if

end loop

if searchFound = false then
    put "No matches found for: ", searchName
end if

close : fileid




Please specify what version of Turing you are using

4.1

Thanks for reading
 
Sponsor
Sponsor
Sponsor
sponsor
Tubby_Kat




PostPosted: Mon May 18, 2009 6:58 pm   Post subject: Re: Changing a Text File Program to a Binary File Program (searching)

-waiting patiently-

-____________________________-
 
Dusk Eagle




PostPosted: Mon May 18, 2009 7:32 pm   Post subject: Re: Changing a Text File Program to a Binary File Program (searching)

Turing:

read : fileid, student.name
read : fileid, student.id
read : fileid, student.grade


You can't do that. You must use:
Turing:

read : fileid, student


This makes the computer read one entire record into student. Then, you can call student.name or student.id or whatever.
 
Tubby_Kat




PostPosted: Tue May 19, 2009 8:02 pm   Post subject: Re: Changing a Text File Program to a Binary File Program (searching)

I tried that and it still doesn't work... -________________-
 
Tubby_Kat




PostPosted: Thu May 21, 2009 6:19 pm   Post subject: Re: Changing a Text File Program to a Binary File Program (searching)

can someone please help?
 
Dusk Eagle




PostPosted: Thu May 21, 2009 7:46 pm   Post subject: Re: Changing a Text File Program to a Binary File Program (searching)

You get the student data, but you never write it to the file. I admit I searched for about 10 minutes before I saw that Wink . Fixing that solves your problem, fortunately.
 
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: