![]() | I/O Format Specifiers for Readings Characters |
A character argument has a format specifier of the following form:
%[*] [width] c
Modifier | Interpretation |
---|---|
Default Functionality | A character is read from the device and stored in the argument. |
* (asterisk) | An asterisk acts as the assignment suppression character. The input is scanned but not assigned to any parameters and is discarded. |
width | Specifies the number of characters to read and store in the argument. The default is 1. A NULL terminator is not appended to the argument. A # may be present in lieu of an integer width modifier, in which case an extra int argument supplies the value. |
HRESULT hr = S_OK; char ch; // Read a single character from the device and store in the argument hr = io.Scanf(_T("%c"), ch); // Field width specifies 5 characters should be read char sz[5]; hr = io.Scanf(_T("%5c"), sz); // sz is NOT NULL terminated // Field width specified using a variable int nWidth = 5; hr = io.Scanf(_T("%#c"), nWidth, sz); // sz is NOT NULL terminated // Reads 5 characters from the device and discards hr = io.Scanf(_T("%*5c"));