LINUX下的整行读取
代码
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
int getline(int fd,char *line,int len)
{
int cur;
char c;
if(line == NULL || len < 0)
{
return -1;
}
for(read(fd,&c,1);
c != '\r' && c != '\n';
*line = c,line++,read(fd,&c,1))
{
}
*line = '\0';
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
int getline(int fd,char *line,int len)
{
int cur;
char c;
if(line == NULL || len < 0)
{
return -1;
}
for(read(fd,&c,1);
c != '\r' && c != '\n';
*line = c,line++,read(fd,&c,1))
{
}
*line = '\0';
return 0;
}
下午上课时候写的,正好晚上要用到。。贴上来