Solved

0d 0a 1a question in closefile

Posted on 1998-08-10
14
1,175 Views
Last Modified: 2011-04-14
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!
0
Comment
Question by:mathematics
  • 4
  • 4
  • 3
  • +1
14 Comments
 
LVL 3

Expert Comment

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

0
 
LVL 5

Expert Comment

by:JimBob091197
Comment Utility
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
0
 
LVL 1

Expert Comment

by:BlackDeath
Comment Utility
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.
0
 

Author Comment

by:mathematics
Comment Utility
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.
0
 
LVL 5

Expert Comment

by:JimBob091197
Comment Utility
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
0
 
LVL 3

Expert Comment

by:vladika
Comment Utility
Hi!

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

0
 
LVL 5

Expert Comment

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

:-)
JB
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Expert Comment

by:BlackDeath
Comment Utility
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.
0
 

Author Comment

by:mathematics
Comment Utility
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.

0
 
LVL 3

Expert Comment

by:vladika
Comment Utility
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.

0
 

Author Comment

by:mathematics
Comment Utility
Thank you,vladika. You answer the question.
0
 
LVL 3

Accepted Solution

by:
vladika earned 120 total points
Comment Utility
Ok. This is my "official answer".

0
 
LVL 1

Expert Comment

by:BlackDeath
Comment Utility
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.
0
 

Author Comment

by:mathematics
Comment Utility
hi Black Death: have a nice day.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now