C Standard Libraries C++

fwscanf()

Declaration

int fwscanf(FILE* qpStream, const wchar_t* kwpFormatString, ...);

Description

This function reads the formatted string "kcpFormatString" from the stream given by the "qpStream" argument. For information on string formatting, see the scanf page. If successful, the function returns the number of fields that were successfully read and assigned. If an error occurs or the end of the stream is reached before the first assignment, the function returns WEOF.

Input File

fwscanf() Input File

Example

#include <iostream>
#include <cwchar>

int main()
{
    using namespace std;
    char* cpFileName = "XoaX.txt";
    FILE* qpFile = fopen(cpFileName, "r");

    // Check that the file could be opened
    if (!qpFile) {
        cout << "Could not open the file!" << endl;
        return 1;
    }

    // Read a string from the file
    wchar_t waReadString[100];
    int iReturn = fwscanf(qpFile, L"%s", waReadString);
    // Check whether the read was successful.
    if (iReturn == WEOF) {
        cout << "Read error!" << endl;
    } else {
        wcout << "Read String = " << waReadString << endl;
    }
    fclose(qpFile);
    return 0;
}

Output

fwscanf() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.