From c5fcf7179a83ef65c86c6a4a390029149e518649 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Tue, 5 Oct 2021 21:49:54 +0200 Subject: Duzy commit ze smieciami --- semestr-4/ask/lista9/ropex.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 semestr-4/ask/lista9/ropex.c (limited to 'semestr-4/ask/lista9/ropex.c') diff --git a/semestr-4/ask/lista9/ropex.c b/semestr-4/ask/lista9/ropex.c new file mode 100644 index 0000000..dbeae12 --- /dev/null +++ b/semestr-4/ask/lista9/ropex.c @@ -0,0 +1,31 @@ +#include +#include +#include + +/* Get string from stdin */ +void readline(FILE *in, char *p) { + int c; + while (true) { + c = fgetc(in); + if (c == EOF || c == '\n') + break; + *p++ = c; + } + *p = '\0'; +} + +void echo(FILE *in) { + char buf[48]; + readline(in, buf); + puts(buf); +} + +int main(int argc, char *argv[]) { + FILE *in = NULL; + if (argc == 2) + in = fopen(argv[1], "rb"); + if (in == NULL) + in = stdin; + echo(in); + return 0; +} -- cgit v1.2.3