Re: function




"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


.



Relevant Pages

  • Re: memory leak?
    ... char, short, int are all 16 bits. ... them rely on EOF being returned by the function. ... value distinct from all unsigned char values. ...
    (microsoft.public.vc.mfc)
  • Re: Is there any GENRIC MACROS in c for INTEGERS,CHARACTERS ?
    ... >> The descriptions of the ctype functions all take int values. ... >> that char is converted to int in this case and that if char is signed ... What is EOF for in this context? ... the 'space' characters and so 0 must be the result. ...
    (comp.lang.c)
  • Re: huffman encoder
    ... > to the specified stream and advances the position indicator for the ... > the error indicator for the stream is set and EOF is returned. ... the whole damn int does not go to the file, only the byte value of the int. ... flushing the, eg, so the last char is not truncated. ...
    (comp.compression)
  • Re: huffman encoder
    ... > to the specified stream and advances the position indicator for the ... > the error indicator for the stream is set and EOF is returned. ... the whole damn int does not go to the file, only the byte value of the int. ... flushing the, eg, so the last char is not truncated. ...
    (comp.compression)
  • Re: [LONG] Re: Request for comment on my tiny learning project: dfighterdb (mytree)
    ... char line; ... static int ui_getINT{ ... Thank you Flash Gordon, you did raise some good points too. ...
    (comp.lang.c)