Re: removing newline character from the buffer read by fgets
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Tue, 28 Nov 2006 04:04:06 +0000 (UTC)
In article <1164682990.902780.19980@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
junky_fellow@xxxxxxxxxxx <junky_fellow@xxxxxxxxxxx> wrote:
Is there any efficcient way of removing the newline character from the
buffer read by
fgets() ?
Is there any library function that is similar to fgets() but also tells
how many
bytes it read into the buffer ?
fgets() terminates the string with the null character, so you can
simply use something along the lines of
/* code fragment follows, not intended as standalone routine */
fgetsresult = fgets( outbuffer, sizeof(outbuffer)-1, stream);
if (fgetsresult == NULL) {
/* handling for no string available */
} else {
size_t newbuflen = strlen(outbuffer);
if (outbuffer[newbuflen - 1] == '\n') outbuffer[newbuflen - 1] = '\0';
}
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
.
- Follow-Ups:
- Re: removing newline character from the buffer read by fgets
- From: Jack Klein
- Re: removing newline character from the buffer read by fgets
- From: Martin Ambuhl
- Re: removing newline character from the buffer read by fgets
- References:
- removing newline character from the buffer read by fgets
- From: junky_fellow@xxxxxxxxxxx
- removing newline character from the buffer read by fgets
- Prev by Date: Re: I am studying c myself .Which books I should read?
- Next by Date: Re: Sharing static variables or function between source files.
- Previous by thread: removing newline character from the buffer read by fgets
- Next by thread: Re: removing newline character from the buffer read by fgets
- Index(es):
Relevant Pages
|
|