Solved

0d 0a 1a question in closefile

Posted on 1998-08-10
14
1,201 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

831 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