Search:

Type: Posts; User: Nominal Animal

Search: Search took 0.04 seconds.

  1. Replies
    30
    Views
    14,308

    I did! :headpalm: I apologize. It is a typo;...

    I did! :headpalm:

    I apologize. It is a typo; the code should of course be


    size_t len;

    len = strlen(line);
    while (len > 0 && (line[len-1] == '\n' || line[len-1] == '\r'))
    len--;
  2. Replies
    30
    Views
    14,308

    The suggestion by Adak causes a buffer underrun...

    The suggestion by Adak causes a buffer underrun bug. It reads a byte just before the buffer, and if that byte equals 10, it replaces it with a zero.

    My suggestion does not have that bug. I would...
  3. Replies
    30
    Views
    14,308

    Embedded nulls, in my experience, are almost...

    Embedded nulls, in my experience, are almost always user errors: reading the wrong file, or such. It does not matter that fgets() is the wrong tool to read such input.

    I'm actually quite upset...
  4. Replies
    30
    Views
    14,308

    If line does not contain a CR or an LF, then...

    If line does not contain a CR or an LF, then strcspn(line, "\r\n") == strlen(line).

    So, what's the problem? Edit: oh, okay: no problem as such, just a different preference.



    strchr() is...
  5. Replies
    30
    Views
    14,308

    To remove the newline (LF or CR LF) at the end of...

    To remove the newline (LF or CR LF) at the end of the line, I recommend


    line[strcspn(line, "\r\n")] = '\0';


    If line is a pointer to the buffer (not the buffer itself), you can use


    line...
Results 1 to 5 of 5