summaryrefslogtreecommitdiffstats
path: root/5/6.c
blob: bd30014a1869dbd5e2fea9bc55a075ae486c51d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <stdlib.h>

int mgetline(char *s, int lim);

int mgetline(char *s, int lim) {
  int i;

  for (i = 0; i < lim - 1 && (*s++ = getchar()) != EOF && *s != '\n'; i++)
    ;

  if (*s == EOF)
    *s = 0;
  else
    *++s = 0;

  return i;
}