Untitled

Anonymous
plain_text
02/10/2026 3:58 PM
932 B
11
Indexable
#include <stdio.h>
#include <unistd.h>     // read, write
#include <sys/types.h>  // ssize_t em POSIX

void mycat(void) {
    ssize_t bytes_read, bytes_written;
    char buffer[1024];

    while ( (bytes_read = read(0, buffer, 1024)) > 0 ) {
        printf("li %zd bytes - %s\n", bytes_read, buffer);

        //escrever para stdout
        bytes_written = write(1, buffer, bytes_read);
        printf("escrevi %zd bytes - %s\n", bytes_written, buffer);
    }
    printf("li %zd bytes\n", bytes_read);
}

int main(int argc, char *argv[]) {
    
    printf("argc: %d\n", argc);

    for (int i = 0; i < argc; i++) {
        printf("argv[%d] = %s\n", i, argv[i]);
    }
    mycat();
    return 0;
}
Editor is loading...
Leave a Comment