How to resolve the algorithm Take notes on the command line step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Take notes on the command line step by step in the PL/I programming language

Table of Contents

Problem Statement

Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then all the arguments, joined with spaces, prepended with a tab, and appended with a trailing newline, are written to NOTES.TXT. If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Take notes on the command line step by step in the PL/I programming language

Source code in the pl/i programming language

NOTES: procedure (text) options (main); /* 8 April 2014 */
   declare text character (100) varying;
   declare note_file file;

   on undefinedfile(note_file) go to file_does_not_exist;
   open file (note_file) title ('/NOTES.TXT,recsize(100),type(text)');
   revert error;

   if text = '' then
      do;
         on endfile (note_file) stop;

         do forever;
            get file (note_file) edit (text) (L);
            put skip list (text);
         end;
      end;
   close file (note_file);
   open file (note_file) output title ('/NOTES.TXT,recsize(100),type(text),append(y)');

   put file (note_file) skip list (DATETIME('DDMmmYYYY'), TIME());
   put file (note_file) skip list (text);
   put file (note_file) skip;

   put skip list ('Appended ' || text || ' to file');

   return;

file_does_not_exist:
   revert undefinedfile (note_file);
   close file (note_file);
   open file (note_file) output title ('/NOTES.TXT,recsize(100),type(text)');
   put file (note_file) skip list (DATETIME('DDMmmYYYY'), TIME());
   put file (note_file) skip list (text);
   put file (note_file) skip;
   put skip list ('The file, NOTES.TXT, has been created');
end NOTES;

  

You may also check:How to resolve the algorithm Copy a string step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Casting out nines step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm 100 doors step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the FOCAL programming language