c-embed
c-embed copied to clipboard
egets does not add the new-line if present and does not add the terminating null byte
Also, I think it should scan for '\n' instead of '\r'.
Regards, GW
I have changed egets to:
char* egets ( char* str, int num, EFILE* stream ){
//if num 0 or 1 stream->pos will not advance
assert(num > 1);
if (eeof(stream) return NULL;
int i = 0;
while(TRUE)
{
//i < (num - 1) so still room for two characters: \n and \0
if ((str[i++] = *(stream->pos++)) == '\n') break;
if (eeof(stream) or (i == (num - 1))) break;
}
str[i] = '\0';
return str;
}