Re: removing newline character from the buffer read by fgets



"junky_fellow@xxxxxxxxxxx" <junky_fellow@xxxxxxxxxxx> writes:
[...]
thanks everyone for your help. In fact, I don't want to use strlen()
or strchr() (for efficiency reasons) to remove the newline
character.

Why not? Is the call to strlen() or strchr() a performance bottleneck
in your program, justifying the extra work of writing an input
function from scratch?

It may be, but if you haven't measured it, you may be applying your
efforts unwisely. Typically reading the input from some external
device will be much slower than scanning a string in memory.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: function
    ... it's fgets that adds the terminating null ... Use strchr to find and remove it before doing the comparison ... any such character is at the end of the line ... string looking for something. ...
    (comp.lang.c)
  • Re: function
    ... it's fgets that adds the terminating null ... Use strchr to find and remove it before doing the comparison ... any such character is at the end of the line ... string looking for something. ...
    (comp.lang.c)
  • Re: c / c++ : is it end of era ?
    ... In the strchr call above, a counted strings implementation can ... character the terminating zero but just makes a bounded ... This is because the memchr routine is probably ...
    (comp.lang.c)
  • Re: strchr function fails to work properly on Windows 2003 Server
    ... The second parameter of strchr is supposed to be a character, ... a pointer. ...
    (microsoft.public.vc.language)
  • Re: c / c++ : is it end of era ?
    ... In the strchr call above, a counted strings implementation can ... character the terminating zero but just makes a bounded ... searching for a zero byte OR the searched character ...
    (comp.lang.c)