Re: function
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Sun, 01 Jun 2008 00:33:58 +0530
Bill Cunningham wrote:
"santosh" <santosh.k83@xxxxxxxxx> wrote in message
news:g1s4e8$igh$3@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Bill Cunningham wrote:
<snip>
Now here's what I tried in error checking that gave me a
warning. must've messed up.
if((fputc(a,fp))!=NULL)
If you read your system's documentation for fputc you'll find that it
returns either the character passed (as an int) or EOF on error. NULL
is the wrong value to be comparing with. The above is better written
as:
if (fputc(ch, stream) == EOF) {
/* error */
}
if((fclose(fp))!=NULL)
Again, fclose will return EOF on failure.
<snip>
I usually don't miss these things in error checking. I was
suprised when
it didn't work but I guess I've had NULL on my mind. Earlier in this
post I wanted to write zeros to a file and found out the proper use
was with the string terminating character '\0' which is a byte with
all the bits turned off.
Not necessarily. It's just a byte with value zero.
Now a questions about the *putc functions. Do
they take and write a char or 8 bits, or an unsigned int?
They take an int and a FILE * parameter and they attempt to write the
int parameter, cast to an unsigned char, to the stream indicated. A
char is commonly, but not necessarily eight bits. It's needs to be at
least eight bits, but could be more, as in the Cray or in most DSPs.
Fputc's
first parameter is an int and I declared an int and gave it the value
of '\0'. If the char is taken from the first int parameter why an int
instead of a char? Is more information needed than the char itself
like padding or the like?
This is I think just for compatibility with fgetc.
.
- Follow-Ups:
- Re: function
- From: pete
- Re: function
- From: Richard
- Re: function
- References:
- function
- From: Bill Cunningham
- Re: function
- From: Joachim Schmitz
- Re: function
- From: Bill Cunningham
- Re: function
- From: Joachim Schmitz
- Re: function
- From: Bill Cunningham
- Re: function
- From: santosh
- Re: function
- From: Bill Cunningham
- function
- Prev by Date: Re: private functions
- Next by Date: Re: function
- Previous by thread: Re: function
- Next by thread: Re: function
- Index(es):
Relevant Pages
|