XINU
lib
fgets.c
Go to the documentation of this file.
1
5
#ifndef NULL
6
#define NULL 0
8
#endif
9
11
extern
int
getc
(
int
);
12
25
char
*
fgets
(
char
*s,
int
n,
int
dev)
26
{
27
int
c = 0;
28
char
*cs;
29
30
cs = s;
31
32
/* Read characters until maximum read length, */
33
/* end of line, or end of file */
34
while
((--n > 0) && ((c =
getc
(dev)) >= 0))
35
{
36
*cs++ = c;
37
if
((
'\n'
== c) || (
'\r'
== c))
38
{
39
break
;
40
}
41
}
42
43
/* Check for EOF or empty string */
44
if
((c < 0) && (cs == s))
45
{
46
return
NULL
;
47
}
48
49
/* Terminate string and return */
50
*cs++ =
'\0'
;
51
return
s;
52
}
fgets
char * fgets(char *s, int n, int dev)
デバイス(ファイル)から文字列を読み込む。
Definition:
fgets.c:25
NULL
#define NULL
NULLを示す値
Definition:
fgets.c:7
getc
int getc(int)
デバイスから1Byte読み込むgetc()のextern宣言
Definition:
getc.c:9
Generated by
1.8.13