summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/getline.c
blob: 8d24aa2b783b4aaf6fefcdf8f7652e40e8a52e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>

getline(s, lim)	/* get line into s, return length */
char s[];
int lim;
{
	int c, i;

	i = 0;
	while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
		s[i++] = c;
	if (c == '\n')
		s[i++] = c;
	s[i] = '\0';
	return(i);
}