fwrite: writes count number of objects : fwrite « stdio.h « C / ANSI-C






fwrite: writes count number of objects


    

//Header file:     #include <stdio.h>  
//Declaration:     size_t fwrite(const void *buf, size_t size, size_t count, FILE *stream); 
//Return:          returns the number of items written on success. Fewer items written means failure. 

  

  #include <stdio.h>
  #include <stdlib.h>

  int main(void)
  {
    FILE *fp;
    float f=12.23;

    if((fp=fopen("test", "wb"))==NULL) {
      printf("Cannot open file.\n");
      exit(1);
    }

    fwrite(&f, sizeof(float), 1, fp);

    fclose(fp);

    return 0;
  }

           
       








Related examples in the same category