fwrite()

Writes a number of bytes from a blob variable to a file.

Synopsis

int fwrite(file f, blob b[, int numBytes]);

Parameters

Parameters Meaning
f File to which should be written
b blob variable
numBytes

Number of bytes to be written. The argument is optional, if it is not given, all bytes in the blob are written.

Return value

In the event of errors, the function returns -1 or EOF otherwise, the number of written characters.

Description

Writes a number of bytes from a blob variable to a file.

Example

Writes 4 bytes and reads 2 bytes to/from a file.

main()
{
  blob target, rtarget;
  int len, pos;
  string s;
  anytype value;
  bool bigendian;
  s = "FFAB003AFF";
  target = s;
  DebugN(target);
  len = 1;
  value = 5;
  bigendian = TRUE;
  DebugN("Blob AppendValue: " + blobAppendValue(target, value, len, bigendian)); //blob length is 6 = FF AB0 3A FF 5
  DebugN(target); //ff ab 0 3a ff 5
  int fr, fw, numW, fcl, err, numR;
  file wf;
  wf = fopen("D:\\BFile.txt", "w");
  numR = 2;
  numW = 4;
  err = ferror(wf);
  fw = fwrite(wf, target, numW);
  DebugN("Number of bytes that could be written:", fw);
  //Output: ["Number of bytes that could be written:"][4]
  fr = fread(wf, rtarget, numR);
  DebugN("Number of bytes that could be read:", fr);
  //Output: ["Number of bytes that could be read:"][2]
  fcl = fclose(wf);
}

Assignment

File functions

Availability

CTRL