fprintfPL()

Writes to a file similar to fprintf() except changes to the current WinCC OA language before converting.

Synopsis

int fprintfPL (file file, string format, [,<type1> var1 [,<type2> var2 ...]] );

Parameter

Parameter Description
file File to be written. Use the constants stdin, stdout, stderr (see Reference Tables).
format output format
var1, var2, ... arguments

Return value

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

Error

If incorrect data types are used or if a file is not open.

Description

Writes to a file similar to fprintf() but uses the current WinCC OA language before converting.

Example

The following example writes three float values into a text file and reads them again from the file.

main()
{
  file f;
  int i;
  dyn_float value;
  value[1]=12.123;
  value[2]=8.0;
  value[3]=3.1;
  f=fopen("C:/TEMP/tfile.TXT","w+"); //creates a file for writing
  and reading
  for (i=1;i<=3;i++) fprintfPL(f,"%5.3f\n",value[i]);
  //writes the float values into the text file
  rewind(f); //back to the beginning of the file
  for (i=1;i<=3;i++)
  {
    fscanfPL(f,"%f",value[i]); //reads the float values from the
    file
    DebugN(value[i]);
  }
  fclose(f);//closes the file
}

Example

The following example writes the current day, month and year into a text file and reads the data from the file again.

main()
{
  file f;
  int err;
  time now = getCurrentTime(); //gets the current time
  int tDay,tMonth,tYear;
  f=fopen("C:/TEMP/TEST.TXT","w"); //creates a new file for
  writing
  err=ferror(f); //searches for file errors
  fprintfPL(f,"Today is : %d %d %d", day(now), month(now),
  year(now)); //writes "Today is"+ current date into a text file
  TEST.TXT
  fclose(f); //closes the file
  f=fopen("C:/TEMP/TEST.TXT","r"); //opens the file for
  reading
  fscanfPL(f,"Today is : %d %d %d", tDay,tMonth,tYear);
  //reads the current date from the text file
  DebugN(tDay,tMonth,tYear);
  err=ferror(f);
  fclose(f);
}

Assignment

File functions

Availability

CTRL