RosettaCodeData/Task/Truncate-a-file/PL-I/truncate-a-file.pli
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

28 lines
950 B
Text

/* 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 ('What is the name of the file to be truncated?');
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 ('/' || filename || ',type(fixed),recsize(1)' )
input;
do i = 1 to n; read file (in) into (ch); c(i) = ch; end;
close file (in);
open file (out) title ('/' || filename || ',append(n),type(fixed),
recsize(' || trim(n) || ')' );
write file (out) from (c);
close file (out);
end;
end truncate_file;