On Thu, 31 May 2012, Jason White <jason(a)jasonjgw.net> wrote:
You could write a function to do this without much
trouble though.
Below is my rough analog to fgets() which takes either \r or \n as the end of
a line. It works because I don't mind getting the occasional empty line in
the middle of the file, programs which can't handle extra empty lines won't
work with this.
int get_line(char *buf, int buf_len, FILE *fp)
{
int c, i = 0;
while((c = fgetc(fp)) != EOF)
{
if(c == '\r' || c == '\n')
{
buf[i] = 0;
return 1;
}
buf[i] = (char)c;
i++;
if(i == buf_len - 1)
{
buf[i] = 0;
return 1;
}
}
if(i > 0)
{
buf[i] = 0;
return 1;
}
return 0;
}
--
My Main Blog
http://etbe.coker.com.au/
My Documents Blog
http://doc.coker.com.au/