fwrite - C stdio.h

C examples for stdio.h:fwrite

Type

function

From


<cstdio>
<stdio.h>

Description

Write block of data to stream

Prototype

size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );

Parameters

ParameterDescription
ptr Pointer to the array of elements to be written.
size Size in bytes of each element to be written.
count Number of elements, each one with a size of size bytes.
stream FILE object.

Return Value

On success, total number of elements written is returned.

Demo Code

#include <stdio.h>

int main ()/*w  w w . j  av  a2 s . c o m*/
{
  FILE * pFile;
  char buffer[] = { 'x' , 'y' , 'z' };

  pFile = fopen ("main.cpp", "wb");

  fwrite (buffer , sizeof(char), sizeof(buffer), pFile);

  fclose (pFile);
  return 0;
}

Related Tutorials