| read |
(Stream stream, String buf, int n) |
yoix.io |
| |
Tries to read
n
characters from
stream
into
buf,
and returns the number of characters read or
-1
at the end-of-stream or when an error occurs.
| |
| Example: |
On a UNIX-like system the program,
import yoix.io.*;
import yoix.stdio.*;
String buf[1024, ...];
File file;
int total;
int count;
if ((file = fopen("/etc/passwd", "r")) != NULL) {
while ((count = read(file, buf, buf@sizeof)) >= 0) {
total += count;
buf += count;
buf[1024] = '\0'; // this grows buf
printf("total=%d\n", total);
}
fclose(file);
}
buf -= total;
printf("%s", buf);
is a reasonably good way to read a large file in small chunks
and at the same time save the entire file in a string.
| | |
| Return: |
int
| | |
| See Also: |
readChar,
readLine,
readStream,
ready
|
|
Yoix is a registered trademark of AT&T Intellectual Property.
|