Link to home
Start Free TrialLog in
Avatar of mathematics
mathematics

asked on

0d 0a 1a question in closefile

When the following codes have run:
  f:TextFile;
  AssignFile(f,'c:\test.txt');
  Rewrite(f);
  Writeln(f,'line one');  Writeln(f,'line two');
  CloseFile(f);
  We dump test.txt
  line one #0d#0a  line two #0d#0a
 In general,we end with 1a.
1. Why did I get the result?
2.How do I gget the correct code?
I think it is easy,thank you!
Avatar of vladika
vladika

 AssignFile(f,'c:\test.txt');
  Rewrite(f);
  Writeln(f,'line one');  Writeln(f,'line two');
  Write(f, #$1a); // !!!!!!!!
  CloseFile(f);

Hi

The dump of the file is correct.  Writeln adds a Carriage Return & Line Feed (CR/LF) to the end of each line.  The code for CR/LF is #13#10, or in Hex this is $0d $0a.

Then, when you call CloseFile, an End-Of-File character is added to the end of your file.  The EOF character is #26, or in hex $1a.

Are you wanting to remove the CR/LF codes from the file?  Try Write instead of Writeln.

Regards,
JB
hi guyz!

i wonder. if. it could b that simple. und worth 100 poinz.
what does maths really wanna know?

what i mean is:
he dumps the text 2 control output.
he knows there's $1A for EOF.
i just can't imagine u told him sumthin' new.

so what the heck is his intention when puttin' 100 poinz out 4 that 1?

rex,

Black Death.
Avatar of mathematics

ASKER

Thank for vladika.
For BlackDeath and JimBob
In fact, thhe codes
     AssignFile(f,'c:\test.txt');
     Rewrite(f);
     Writeln(f,'line one');  Writeln(f,'line two');
     CloseFile(f);
can't end the code 1a. So the question was not answered.
Anyway,Thank exverybody.
Hi

If you want to put $1a (= #26) at the end of the file, why don't you do this:

var
  f: TextFile;
begin
  AssignFile(f, 'C:\Test.txt');
  Rewrite(f);
  Writeln(f, 'Line One');
  Writeln(f, 'Line Two');
  Write(f, #26);
  CloseFile(f);
end;

JB
Hi!

Sorry, but I did not understand is my comment correct?
If yes, can I post it as answer?

Indeed vladika, that's what I was wondering...
I'm a bit confused at to what is needed here!!

:-)
JB
hey, maths!

so what is your *question*?

respecting your 2 points:
1. - because this result is correct
2. - whaddaya expect 2 b the 'correct' result?

do u mean the dump should put out $1A as last character, because the file has an end (and thus - eof?) ?
did u ever take a look in2 a FAT?
and saw the eof's?
whaddaya think - could it possibly b that a dump stops dumping when reaching eof?

if you want 2 c the eof on screen, u've gotta trace the FAT from the beginning of the file 2 its end (happy jumpin') plus 1 (which will then b 'EOF').

if this is what u meant. pleez tell us. otherwise i'll check off, cos there really ain't nothin 2 answer...

nevermind, maths.

have a nice day, think about different things (i mean, is any functionality affected by this? does it *really* matter?)

bye,

Black Death.
Thank for vladika.
Your comment is only giving half answer of the problem.
But if the answer of "1. Why did I get the result? " is
"Closefile in the  C++ Builder / Java / Delphi / Visula C++ /any programming tool  for
Windows 95
will be not giving the code '1a' for text file".
Or I do something wrong for i/o access.

I think there is no difference between common file and text file at Windows 95 point of view.
When you open file Delphi call CreateFile function.
CreateFile is WinAPI function and you cannot say that openning file is text file.

When you use WriteLn procedure
Delphi (not Windows) automatically add #13#10 sequence in your file.

When you close file Delphi call CloseHandle function.
CloseHandle is WinAPI function.
Since there is no difference between text file and common file
CloseHandle not add #$1a in the end of file.

So you must add #$1a manually in your code.

Thank you,vladika. You answer the question.
ASKER CERTIFIED SOLUTION
Avatar of vladika
vladika

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi maths.

sorry for being rude if i was.
now that you've got your answer i know what your question was.
so - never mind my silly comments.

have a nice day,

Black Death.
hi Black Death: have a nice day.