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

Username:   Password: 
 RegisterRegister   
 How to output a text from txt file
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
salehyassin




PostPosted: Fri Jun 13, 2008 12:07 pm   Post subject: How to output a text from txt file

Hi
I would like to ask about how to load a txt file for example info.txt and output it as it is written in the file using Font.Draw

I tried

var f1 : int
var text : string

open : f1,"info.txt",read
read : f1,text

Font.Draw(text,20,20,font,black)

but the problem is the program write the text but in a line not paragraph as written in the txt file

So my question is how to output a text using Font.Draw from a txt file.

Thanks



info.zip
 Description:
Here is an example

Download
 Filename:  info.zip
 Filesize:  404 Bytes
 Downloaded:  73 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Fri Jun 13, 2008 12:43 pm   Post subject: RE:How to output a text from txt file

You don't seem to understand the concept of a "text file" very well, so I'll explain it.

A "text file" contains only text. No formatting, nothing special - just text. Your source code (.t files) are an example of text files - the colour coding is supplied ENTIRELY by the Turing program, and isn't actually in your .t files. Open them up in Notepad and you'll see there isn't any colour / bolding.

If you want the file to represent a coloured / formatted section of text, you need to output a special file format that tells the program reading it how to format the text. If you choose this route, then you'll have to read up on a file format (for example, HTML or RTF [rich text format]) and output special formatting information along with the actual text in the file. This is decidedly more complicated.

If you tell us exactly WHY you want to write formatted text to a file, we might be able to point you towards a better solution to the problem.
Light




PostPosted: Fri Jun 13, 2008 1:19 pm   Post subject: RE:How to output a text from txt file

If you mean that it is ignoring line breaks and is not wrapping when it gets to the end of the screen the problem is that font draw is only meant for outputting text in a graphical display mode and in a singal line.

You will have to add logic to start a new line when the length of a line is to long for the screen. You start a new line by calling Font.Draw with new a location lower then the first and with the rest of the text.

An example:
Turing:

var longText : string := "This is a long string that also has some\npage breaks. la la la la la la la la la\nhello world!"
var i : int := 1
var count : int := 0
var shortText : array 1 .. 20 of string
shortText(1) := ""
var maxlength : int := 50

for k : 1 .. length (longText)
    count += 1
    if count >= maxlength or longText (k) = '\n' then
        i += 1
        count := 0
        shortText (i) := ""
    end if

    if longText (k) not= '\n' then
        shortText (i) += longText (k)
        count += 1
    end if
end for


for k : 1 .. i
    Font.Draw (shortText (k), 0, maxy - k * 10, defFontID, black)
end for


This may seem complicated but what it does is make an array of strings that are of length maxlength at most. It also starts a new array element when a line break '\n' is hit to preservers the line breaks in the string.

It then loops threw the array and prints it to the screen at slightly lower locations each time.

Note: the upper bound of shortText must fit all the short strings or you will get errors, you could use flexible arrays if you like but this was just a simple example.
DemonWasp




PostPosted: Fri Jun 13, 2008 1:33 pm   Post subject: RE:How to output a text from txt file

Whoops. I totally misread your question. My mistake, sorry. Light seems to have a *much* better answer.
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: