Re: function
- From: "Bill Cunningham" <nospam@xxxxxxxxx>
- Date: Sat, 31 May 2008 18:42:16 GMT
"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. Now a questions about the *putc functions. Do they take and write a
char or 8 bits, or an unsigned int? 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?
Bill
.
- Follow-Ups:
- Re: function
- From: santosh
- 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
- 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
|