Solved

0d 0a 1a question in closefile

Posted on 1998-08-10
14
1,190 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 82
Delphi Mdi application Child forms get behind control 7 162
Delphi 2 51
Performance of SQL statement 37 101
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

867 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

21 Experts available now in Live!

Get 1:1 Help Now