Truncate a file: Difference between revisions

Modified to read in file name
(New entry for PL/I)
(Modified to read in file name)
Line 380:
=={{header|PL/I}}==
<lang>
/* Parameters to be read in by the program are: */
/* 1. the name of the file to be truncated, and */
/* 2. the size of file after truncation. */
 
truncate_file: procedure options (main); /* 12 July 2012 */
declare (i, n) fixed binary (31);
declare filename character(50) varying;
declare in file record input, out file record output;
 
put list ('What is the lengthname of the file to be retainedtruncated?');
get edit (filename) (L);
put ('What is the length of file to be retained?');
get (n);
 
begin;
declare c(n) character (1), ch character (1);
 
open file (in) title ('/out.dat' || filename || ',type(fixed),recsize(1)' ) input;
input;
do i = 1 to n; read file (in) into (ch); c(i) = ch; end;
close file (in);
 
open file (out) title ('/out.dat' || filename || ',append(n),type(fixed),recsize(' ||
recsize(' || trim(n) || ')' );
write file (out) from (c);
close file (out);