Re: equivalent of chomp in perl



CBFalconer <cbfalconer@xxxxxxxxx> writes:
Keith Thompson wrote:
CBFalconer <cbfalconer@xxxxxxxxx> writes:
lnatz wrote:

Is there an equivalent to the perl command chomp in C? And if
there is no exact equivalent command, how would I go about
removing the "\n" at the end of a stdin?

int flushln(FILE *f) {
int ch;

while (('\n' != (ch = getc(f))) && (EOF != ch)) continue;
return ch;
}

That's a useful function, but it's doesn't bear any particular
resemblance to Perl's chomp function.

Probably so, but I suspect it is the answer to the OPs real
question, which was not well defined.

If you happen to know what Perl's chomp function does (which is
admittedly off-topic), the question is perfectly well defined, though
it could have been worded a bit better. The OP wants to remove a
trailing '\n' from a string (for example, from a string representing a
line read by fgets(). There's no indication that he wanted to discard
a line of input.

--
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: equivalent of chomp in perl
    ... removing the "\n" at the end of a stdin? ... int flushln{ ... If you happen to know what Perl's chomp function does (which is ...
    (comp.lang.c)
  • Re: Newbie question on string operators in C#
    ... This is excerpted from a base conversion function that converts s (a ... string representing a number in any base 2 to 36) into a string representing ... Does it simply convert the two characters into their ASCII numbers, ... In fact, the (int) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: equivalent of chomp in perl
    ... int flushln{ ... resemblance to Perl's chomp function. ... chomp is used for a specific purpose, which is removing ... the newline from a whole line read from input. ...
    (comp.lang.c)