代码
标签 :my_fgets.c
#include<stdio.h>
char *my_fgets(char *s,int maxlen,FILE *fp)
{
register int c;
register char *cs;
cs = s;
while(--maxlen >0 && (c = getc(fp)) != EOF)
if((*cs++ = c) == '\n')
break;
*cs = '\0';
return (c == EOF && cs == s)? NULL: cs;
}
标签 : my_getline.c
#include<stdio.h>
#include<string.h>
/* getline : read a line, return lenght */
int my_getline(char *line, int max,FILE *fp)
{
if ( (my_fgets(line, max, fp)) == NULL)
return 0;
else
return strlen(line);
}
错误
[root@server0 fgets]# gcc -c my_getline.c
my_getline.c: In function ‘my_getline’:
my_getline.c:7:36: warning: comparison between pointer and integer [enabled by default]
if ( (my_fgets(line, max, fp)) == NULL)
^
请问为什么会有这错误?
我在stackoverflow上提问得到了答案:
https://stackoverflow.com/que...