home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
PROGRAMM
/
SNIP0492.ZIP
/
FIGETS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-12
|
1KB
|
43 lines
/*
** figets like fgets only works backward from filepos pos instead of
** forward from the current filepointer
**
** returns fileposition of the begin of line read
**
** by Jan Vroonhof
*/
#define MAXLEN 90
long pascal figets(FILE *file,char *buffer,long pos)
{
char *i;
long aap;
aap = (pos - MAXLEN > 0 ? pos-MAXLEN : 0L);
fseek(file, aap, SEEK_SET);
fread(buffer + 100, 1, MAXLEN, file);
buffer[pos - aap + 100] = 0;
i = strrchr(buffer + 100, '\n');
if (i)
{
*i = 0;
i = strrchr(buffer + 100, '\n');
if (i)
{
strcpy(buffer, i + 1);
return aap + (i - buffer - 100) + 1;
}
else
{
strcpy(buffer, buffer + 100);
return (aap ? -1L : 0L);
}
}
else
{
strcpy(buffer, buffer + 100);
return -1L;
}
}