News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Writing text to a file

Started by carlottagp, May 17, 2006, 07:43:43 PM

Previous topic - Next topic

carlottagp

I am writing simple 16-bit programs for arithmetic adventures, such as
calculating factorials, Fibonacci numbers, and the like.  I seem to be OK
with writing data from a buffer to a file (with int 21h, AH = 40h), but
I would like to write text to the same file, for headings and descriptive
material.  Do I have to create a file in advance with a text editor, and
read it into my programs (with AH = 3Fh), or is there a way to include
various lines of text into my .asm file and write them directly to the file
as required?

Thanks for any suggestions.

Michael

ChrisLeslie

Hi carlottagp,

I think that to write to a file, and then overwrite to the same file with text at specific places, if that is what you are asking, would be rather cumbersome.
For your case I would open/create the file from your program and write the various entries and the text headings and descriptions as string text in the order that they occur in processing if that is possible. Keep in mind where you write cr's and lf's, as well as spaces, so that your file becomes easy to visualize later on with columns that line up etc. Alternatively you could create an array into which you can insert what you want in any position, and then write the whole array to disk file at the end.

Chris

carlottagp

Chris,

Thanks for your input.  I am not actually trying to overwrite my file, but - for instance - to write
headings first, and then the data. What I don't know how to do is to write "string text", and
then go on from there.  Since (AH = 40h) requires data to be in a buffer, all I can think of is
to load a buffer, one character at a time, and then write it.  For text, this will be a very
long and inefficient process, obviously; presumably the characters would be part of  the . DATA
segment.  I'd like to be able to include a text string in the data, such as the string I use for
definition of the file, via the (AX = 716C) procedure.  Hope I'm explaining myself clearly...

Michael

MichaelW

I'm not sure I understand what you are attempting to do, but function 40h does not care what the data is or where it is, so you could just set DX to the offset address of the string in the data section and CX to the length.

eschew obfuscation