aboutsummaryrefslogtreecommitdiff
path: root/semestr-4/ask/lista9/ropex.c
blob: dbeae12ab892a8080222dab920c16cc3578c00de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

/* 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;
}