Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egets does not add the new-line if present and does not add the terminating null byte #5

Open
gwiesenekker opened this issue Dec 19, 2022 · 1 comment

Comments

@gwiesenekker
Copy link

gwiesenekker commented Dec 19, 2022

Also, I think it should scan for '\n' instead of '\r'.

Regards,
GW

@gwiesenekker
Copy link
Author

gwiesenekker commented Dec 27, 2022

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant