Solved

0d 0a 1a question in closefile

Posted on 1998-08-10
14
1,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
14 Comments
 
LVL 3

Expert Comment

by:vladika
ID: 1361783
 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
ID: 1361784
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
ID: 1361785
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mathematics
ID: 1361786
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
ID: 1361787
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
ID: 1361788
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
ID: 1361789
Indeed vladika, that's what I was wondering...
I'm a bit confused at to what is needed here!!

:-)
JB
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1361790
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
ID: 1361791
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
ID: 1361792
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
ID: 1361793
Thank you,vladika. You answer the question.
0
 
LVL 3

Accepted Solution

by:
vladika earned 120 total points
ID: 1361794
Ok. This is my "official answer".

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1361795
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
ID: 1361796
hi Black Death: have a nice day.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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