PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] Removing trailing newlines from input from file(s)
Date: Sunday, 15 Mar 2020, 13:21:37


    > Message Posted By: Unknown
    >
    > When using getline() to get lines from a file, is there an easier way to
    > remove trailing newlines than writing a function that traverses the line
    > buffer after calling getline() until it finds a newline and then
    > reallocating the line buffer and removing the newline if it finds one?

See strrchr() (or "man strrchr" for details).

However, since

  6. The prohibition against arrays means that you may not use malloc() or
     realloc() or calloc() outside the file that implements the Deque ADT
     (other than their use by getline() and in the Standard I/O Library).
   
you may NOT reallocate the line buffer.

--Stan-
PREV INDEX NEXT