File input/output: Difference between revisions
Content added Content deleted
imported>Collin (→Rust: Use `std::fs::{read, write}` to make the solution simpler) |
imported>KayproKid (Added S-BASIC example) |
||
Line 3,565: | Line 3,565: | ||
process::exit(code); |
process::exit(code); |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
=={{header|S-BASIC}}== |
|||
Surprisingly, S-BASIC has no EOF function, so we have to rely on error trapping to signal end of file. S-BASIC stores its error codes at 103H, and we can position a base-located variable there to retrieve it. The result is something of a kludge, but it works. Other S-BASIC preculiarities are explained by the comments. |
|||
<syntaxhighlight lang="BASIC"> |
|||
comment |
|||
Preserve file channel #0 (the console) while declaring channels |
|||
#2 and #3 as sequential-access ASCII files. |
|||
end |
|||
files d, sa, sa |
|||
var s = string:255 |
|||
based errcode = integer |
|||
base errcode at 103H |
|||
comment |
|||
CP/M expects upper case file names, but S-BASIC does not |
|||
automatically convert file name arguments to upper case, so we |
|||
have to do that ourself. |
|||
end |
|||
create "OUTPUT.TXT" |
|||
open #1,"INPUT.TXT" |
|||
open #2,"OUTPUT.TXT" |
|||
comment |
|||
S-BASIC allows alphanumeric line "numbers" (which are treated simply |
|||
as labels) as the target of GOTO and GOSUB statements, but the first |
|||
character must be a digit |
|||
end |
|||
on error goto 9done |
|||
rem - runtime error code 15 signals read past end of file |
|||
while errcode <> 15 do |
|||
begin |
|||
input3 #1; s |
|||
print #2; s |
|||
end |
|||
9done |
|||
close #1 |
|||
close #2 |
|||
end |
|||
</syntaxhighlight> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |