#include #include int main(int argc, char** argv) { ssize_t read; char* buffer = 0; size_t buf_size = 0; // getline is a GNU non-standard extension // it is safer than fgets while ( (read = getline(&buffer, &buf_size, stdin)) > 0 ) { if (buffer[read-1] == '\n') { // chop trailing newline buffer[read-1] = 0; } fprintf(stdout, "read %d bytes ... bufsize %d bytes ... text: %s\n", read, buf_size, buffer); } free(buffer); return 0; }