fixed getline function

This commit is contained in:
Pavol Marko 2004-03-24 18:35:04 +00:00
parent a9a46e20b2
commit 012507c38a

View File

@ -94,6 +94,7 @@ File& operator>>( File& f, char* n )
int File::getline( char* buf, int sz ) int File::getline( char* buf, int sz )
{ {
int a = sz; int a = sz;
char *origBuf = buf;
if ( *this ) if ( *this )
{ {
int c; int c;
@ -101,6 +102,15 @@ int File::getline( char* buf, int sz )
*buf++ = c; *buf++ = c;
*buf = 0; *buf = 0;
} }
// trim 0x0a and 0x0d characters at the end
while (buf != origBuf)
{
if (*buf == 0x0a || *buf == 0x0d)
*buf = 0;
--buf;
}
return a - sz; return a - sz;
} }