You write numbers to the file of type integer
, that is, in fact it is a binary file. A text file consists of characters. When you open a file through a notebook, it displays the character codes of the numbers you entered, and the characters with an ASCII code less than 32 are unreadable. To enter the numbers you need displayed
Change file format to Text
f: Text;
convert number to string with Str
To do this, add the variable S: string
to the Var
section.
and before doing the conversion do
Instead of write(f ,a[i]);
:
Str(a[i], S); Write(f, S + ' ');
For readability add a space. Then the file will be readable, but if you conduct further processing, it is better to leave the file in integer
format, since it is more convenient to use the binary format when processing the file. You immediately read the numbers in the native format without conversion.
It all depends on the tasks.
To convert a string to a number, use the Val
function.
The chr
function does not work in this case, because the file format is not file of char
.