Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* exercise on UNIX file system */
- /* useful characters: [] # */
- # include <stdio.h>
- # include <string.h>
- # define errormsg(x) { puts(x); exit(1); }
- # define BUFFER 1024
- int main(int argc, char * argv[])
- {
- int current, previous; // current and previous chars/bytes? read
- char *buffer[BUFFER];
- int result = read(0, buffer, BUFFER); // reads everything that can be stored FROM STDIN
- while(result) // loops for as long as there is data to read
- {
- current = 0;
- previous = 0;
- do {
- previous = previous + current;
- result = write(1, &buffer, result - previous); // writes everything TO STDOUT
- } while(current + previous < result); // ... until the space runs out
- result = read(0, buffer, BUFFER); // begins reading again
- }
- }
- // why current + previous < result? can't all chars/bytes be written just by using:
- // result = write(1, &buffer, BUFFER) ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement