Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:52:48+00:00 2026-06-18T08:52:48+00:00

Following is a simple console application then generates ten sets of 3 random numbers

  • 0

Following is a simple console application then generates ten sets of 3 random numbers and prints them out to both the console window and a text file, ‘Output.txt’.

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;
var
  outputFile: TextFile;
  i: Integer;
  a,b,c: Single;
begin
  try
    Randomize;
    AssignFile(outputFile, 'Output.txt');
    ReWrite(outputFile);
    for i := 0 to 9 do
    begin
      a := Random;
      b := Random;
      c := Random;
      WriteLn(FloatToStr(a) + Char(9) + FloatToStr(b) + Char(9) + FloatToStr(c));
      WriteLn(outputFile, FloatToStr(a) + Char(9) + FloatToStr(b) + Char(9) + FloatToStr(c));
    end;
    Close(outputFile);
    Sleep(10000);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

The text file holds the same information as the console window only if I include line 26:

Close(outputFile);

If I omit this from the code I would expect to get the same data printed to the text file anyway but what is actually printed in the text file is the same for the first 9 lines and then an incomplete final line.

Why does this happen? By what process does the final line only get written in part due to the omission of the Close procedure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:52:49+00:00Added an answer on June 18, 2026 at 8:52 am

    This is caused because the file output is buffered. When you close the file it causes the buffer to be flushed and the remaining content put out to disk.

    An alternative is to perform a Flush(outputFile) after the WriteLn for the file, it will accomplish the same thing, but at the expense of performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple console application where I have the following setup: public interface
I am new to visual studio.I have created a simple console application and then
I have the following function //simple function with parameters and variable function thirdfunction(a,b,c,d){ console.log(the
I'm creating a console application to read a local file using the following code:
Im developing a simple console application using java. I want to display currently running
I have a batch file which starts multiple instances of simple console application (Hello
I am trying to create a simple console based java application, which requires users
I have a simple console application that outputs a menu and waits for user
Consider this simple console application: using System; namespace Demo { class Program { static
I am using EmguCV 2.3.0.1416 from a simple console application (.net 4.0 and c#)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.