Re: function



santosh <santosh.k83@xxxxxxxxx> writes:

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.

Why on earth would you say that? It serves ZERO purpose whatsoever to
someone with such obvious difficulties as Bill.. All you will do is
confuse the guy more.


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.

Ditto. Refer the man to the man page or whatever.
.



Relevant Pages