uniFPrintf()
Writes to a file.
Synopsis
int uniFPrintf(file file, string format, [,<type1> var1 [,<type2>
var2...]]);
Parameters
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
Errors
If incorrect data types are used or if a file is not open.
Description
Writes outputs to the file "file"; under the specified format. The format string format contains two types of elements. Usual characters that are copied to the output and (optional) conversion specifications that define the conversion and output of the next-following (optional) argument var1, var2 and so on of uniFPrintf(). The function uniFPrintf() returns the number of written characters or in the event of an error, a negative number. Each conversion specification starts with the character % and ends with a conversion character. The following flags can be placed in between:
Flags | No or several flags in any order. |
- | The converted argument is aligned left-justified. If no minus sign has been specified, the alignment will be right-justified. |
space | Similar to the flag + (output with positive sign if the value has been signed). A blank space is outputted instead of a plus sign. If the flags space and + are specified together, the flag + has the higher priority. |
# | Output is in an alternative format. A detailed description of the individual conversion characters follows in the next section. |
-
width: The indication of the accuracy is optional. The exact meaning depends on the type of the conversion performed.
-
prec: Indication of the accuracy is optional. The accuracy indicates the number of digits that are output after the decimal point. The accuracy is entered after the decimal point. If the decimal point is used without specifying the accuracy, no places after the decimal point will be output. The specification of the accuracy only applies to the conversionse,E, f,g andG.
-
format: A letter that defines the type of conversion.
Description | Meaning of width | Meaning of the flag # | |
---|---|---|---|
d | The argument is represented as a decimal number |
Minimum number of represented characters. Otherwise filled with blank spaces. The default value is 1. The output of the number zero with a width of zero results in no character! |
Not defined. |
o | The argument is represented as an octal number without leading zeros. | see d | Places a 0 in front of the result is greater than zero. |
u | The argument is displayed as an unsigned decimal number. | see d | Not defined. |
x | The argument is represented as a hexadecimal number (without leading 0x). The letters abcdef are used. | see d | Places a 0 in front of the result is greater than zero. |
X | Like x. But the letters ABCDEF are used. | see d | Places an 0 in front of the result is greater than zero. |
f |
The argument float/double is represented as a decimal number. [ - ] ddd.ddd is the default: |
Minimum number of represented characters. May be extended for the required accuracy by specifying a decimal point and places after the decimal point. When a decimal point is output, at least one character is output before the decimal point. |
Output of a decimal point even if no spaces after the decimal point follow. |
e |
The argument float/double is represented as an exponent number in the format [ - ] d.ddde dd The exponent always contains at least two places. If the value is zero, the exponent is zero. |
seef | seef |
E | Similar to e. Instead of e, E is used. | seef | seef |
g | Similar to for e, but dependent on the value. The conversion type e is only used when the exponent is less than -4 or greater than the accuracy. | see f | see f |
G | Similar tog. An E is output instead of an e. | see f | see f |
s | The argument is a string. Individual characters are output from the string until either a null character ("/0") has been reached or as many characters as required for accuracy. | Minimum number of represented characters. | Not defined. |
Example
The following example writes six characters to a temporary file.
const int STRING_COUNT = 3;
main()
{
file f, f1;
int i, j;
dyn_string chinChar;
chinChar=makeDynString("这;这边的;今;这事;上述的事;后者","的第三 人称单数;直叙法;现在式",
"名 本文;原文;圣经文句;题;题目");
DebugN("Chinese characters:", chinChar);
//Opens a new file for writing and reading
f=fopen("C:/TEMP/tfile5.TXT","w+");
f1=fopen("C:/TEMP/tfile6.TXT","w+");
//Writes 6 characters to the files
for (i=1;i<=STRING_COUNT;i++)
uniFPrintf(f,"%.6s",chinChar[i]);
for (j=1;j<=STRING_COUNT;j++) fprintf(f1,"%.6s",chinChar[j]);
/*Characters are not correctly written since fprintf is used
for
chinese characters*/
fclose(f);
fclose(f1);
}
Assignment
String functions
Availability
CTRL