| tellCount |
(Stream stream [, int mode]) |
yoix.io |
| |
Returns a double that represents the number of characters read from
or written to
stream,
or
-1
if there was an error.
If the stream is open for concurrent reading and writing, then it will
be necessary to supply a
mode
to avoid defaulting to
READ
mode.
| |
| Example: |
The following example, while similar to that provided with the documentation
for
offsetBytes,
does emphasize that
tellCount
is counting the total characters read from or written to a stream.
Other differences between the built-ins is that
offsetBytes
counts bytes rather than characters and it only works with read / write
File
streams.
Incidentally, the use of
iso8859-1
encoding is made explicit to emphasize that in this example one character
equals one byte.
import yoix.io.*;
import yoix.stdio.*;
import yoix.system.*;
File f = {
String name = tmpnam(null);
String encoding = "ISO8859_1";
int mode = READ|WRITE;
int open = true;
};
if (offsetSupported(f)) {
f.nextbuf = "Midway in our life's journey, I went astray\n\
TYPO the straight road and woke to find myself\n\
alone in a dark wood.";
double pos = offsetBytes(f);
offsetBytes(f, 0);
fprintf(stdout, "First line: \"%s\"\n\n", f.nextline);
double w_chars = tellCount(f, WRITE);
double r_chars = tellCount(f, READ);
fprintf(stderr, "Current file pointer: %d\n", offsetBytes(f));
fprintf(stderr, "Saved offset is at: %d\n", pos);
fprintf(stderr, "Characters written: %d\n", tellCount(f, WRITE));
fprintf(stderr, "Characters read: %d\n\n", tellCount(f, READ));
f.nextbuf = "from";
fprintf(stderr, "Current file pointer: %d\n", offsetBytes(f));
fprintf(stderr, "Saved offset is at: %d\n", pos);
fprintf(stderr, "Characters written: %d\n", tellCount(f, WRITE));
fprintf(stderr, "Characters read: %d\n\n", tellCount(f, READ));
offsetBytes(f, pos);
f.nextbuf = " How shall I say\n\n\
what wood that was! I never saw so drear,\n\
so rank, so arduous a wilderness!\n\
Its very memory gives a shape to fear.\n\n";
pos = offsetBytes(f);
offsetBytes(f, 0);
stdout.nextbuf = f.nextbuf;
fprintf(stderr, "Current file pointer: %d\n", offsetBytes(f));
fprintf(stderr, "Saved offset is at: %d\n", pos);
fprintf(stderr, "Characters written: %d\n", tellCount(f, WRITE));
fprintf(stderr, "Characters read: %d\n", tellCount(f, READ));
} else fprintf(stderr, "Offset operations not supported\n");
f.open = false;
unlink(f.fullname);
The output from standard output and standard error combined would look like:
First line: "Midway in our life's journey, I went astray"
Current file pointer: 44
Saved offset is at: 112
Characters written: 112
Characters read: 44
Current file pointer: 48
Saved offset is at: 112
Characters written: 116
Characters read: 44
Midway in our life's journey, I went astray
from the straight road and woke to find myself
alone in a dark wood. How shall I say
what wood that was! I never saw so drear,
so rank, so arduous a wilderness!
Its very memory gives a shape to fear.
Current file pointer: 248
Saved offset is at: 248
Characters written: 252
Characters read: 292
| | |
| Return: |
double
| | |
| See Also: |
offsetBytes
|
|
Yoix is a registered trademark of AT&T Inc.
|
|