Re: function




"Joachim Schmitz" <nospam.jojo@xxxxxxxxxxxxxxxxxx> wrote in message
news:g1rq2v$nf9$1@xxxxxxxxxxxx

[snip]

Still needs some error checking (num>=0, fp != NULL, fclose and fput
worked)

I can get that part. I think.
Yep, left as an excercise to the reader 8-)

Now here's what I tried in error checking that gave me a warning. I
must've messed up.

if((fputc(a,fp))!=NULL)
if((fclose(fp))!=NULL)

comparing argument with a without a cast or something like that the compiler
said. Without cast and comparing was mentioned by the compiler but it
compiled and didn't work. So I tried this.

if((fputc(a,fp))==NULL)
puts("fputc error");

When I ran the binary fputc error was mentioned 10 times. My 2nd arg was 10.

Bill


.



Relevant Pages

  • Re: Copying an array slice (Was: Re: Difficulties with passing multi-dimensional arrays)
    ... <snip examples which got garbled, look upthread if needed, except> ... hence convertible w/o cast> ... > removes the warning. ... > compile under a standards-compliant compiler". ...
    (comp.lang.c)
  • Re: (FAQ details:) malloc(), void * and casts
    ... The rationale for this is that 1) the ... cast is not needed and 2) the cast may mask errors. ... correct C++ compiler. ... But it is an extraneous warning. ...
    (comp.lang.c)
  • Re: (FAQ details:) malloc(), void * and casts
    ... cast is not needed and 2) the cast may mask errors. ... it's quite a good rationale when taken with the very solid ... correct C++ compiler. ... It silences at least one warning on all of my 'modern' compilers. ...
    (comp.lang.c)
  • Re: Array of pointers in a struct
    ... >>cast it, there's a warning, if I don't, there isn't. ... > This is exactly the warning you need to avoid undefined behavior. ... > warning tells you the compiler thinks malloc is returning an integer. ...
    (comp.lang.c)
  • Re: Reading a string of unknown size
    ... "Don't cast return value of mallocin C. ... of it's prototype,, and, on ... The compiler may emit different callsite code based on these. ... will not issue at least a warning as soon as it detects this scenario. ...
    (comp.lang.c)