Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/string/io

Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/string/io

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras
Filename: Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/string/io
Read OK:
File size: 0147 bytes
Load address: 0000
Exec address: 0000
File contents
/*  GCW  06/06/94             */
/* String input/output        */

/* Read a ctrl-char terminated string from file */
gets(file)
{
 local s, c;
 s = "";
 while ((c = getc(file)) != EOF && c > 31)
   s += c;
 return s;
}

/* Write a string to a file */
puts(s,file)
{
 local i;
 for (i=0;i<sizeof(s);i++)
    putc(s[i],file);
}
00000000  2f 2a 20 20 47 43 57 20  20 30 36 2f 30 36 2f 39  |/*  GCW  06/06/9|
00000010  34 20 20 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |4             */|
00000020  0a 2f 2a 20 53 74 72 69  6e 67 20 69 6e 70 75 74  |./* String input|
00000030  2f 6f 75 74 70 75 74 20  20 20 20 20 20 20 20 2a  |/output        *|
00000040  2f 0a 0a 2f 2a 20 52 65  61 64 20 61 20 63 74 72  |/../* Read a ctr|
00000050  6c 2d 63 68 61 72 20 74  65 72 6d 69 6e 61 74 65  |l-char terminate|
00000060  64 20 73 74 72 69 6e 67  20 66 72 6f 6d 20 66 69  |d string from fi|
00000070  6c 65 20 2a 2f 0a 67 65  74 73 28 66 69 6c 65 29  |le */.gets(file)|
00000080  0a 7b 0a 20 6c 6f 63 61  6c 20 73 2c 20 63 3b 0a  |.{. local s, c;.|
00000090  20 73 20 3d 20 22 22 3b  0a 20 77 68 69 6c 65 20  | s = "";. while |
000000a0  28 28 63 20 3d 20 67 65  74 63 28 66 69 6c 65 29  |((c = getc(file)|
000000b0  29 20 21 3d 20 45 4f 46  20 26 26 20 63 20 3e 20  |) != EOF && c > |
000000c0  33 31 29 0a 20 20 20 73  20 2b 3d 20 63 3b 0a 20  |31).   s += c;. |
000000d0  72 65 74 75 72 6e 20 73  3b 0a 7d 0a 0a 2f 2a 20  |return s;.}../* |
000000e0  57 72 69 74 65 20 61 20  73 74 72 69 6e 67 20 74  |Write a string t|
000000f0  6f 20 61 20 66 69 6c 65  20 2a 2f 0a 70 75 74 73  |o a file */.puts|
00000100  28 73 2c 66 69 6c 65 29  0a 7b 0a 20 6c 6f 63 61  |(s,file).{. loca|
00000110  6c 20 69 3b 0a 20 66 6f  72 20 28 69 3d 30 3b 69  |l i;. for (i=0;i|
00000120  3c 73 69 7a 65 6f 66 28  73 29 3b 69 2b 2b 29 0a  |<sizeof(s);i++).|
00000130  20 20 20 20 70 75 74 63  28 73 5b 69 5d 2c 66 69  |    putc(s[i],fi|
00000140  6c 65 29 3b 0a 7d 0a                              |le);.}.|
00000147