C Standard Libraries C++

swscanf()

Declaration

int swscanf(const wchar_t* kwpBuffer,
            const wchar_t* kwpFormatString, ...);

Description

This function reads data from the wide character string "kwpBuffer" and put them into the arguments passed in after the formatted string. The string "kwpFormatString" specifies how data is read into the arguments. The function returns an integer to indicate how many arguments were successfully read. Otherwise, the function returns WEOF to indicate an error or that the end of the string was reached before an argument was read.

Example

#include <cwchar>

int main()
{
    const wchar_t kwaBuffer[] = L"XoaX.net 87";
    wchar_t waString[11];
    int iInteger = 0;

    // Read a string of max size 10 and then an integer
    int iSize = swscanf(kwaBuffer, L"%10ws %d", waString, &iInteger);
    wprintf(L"String = %ws\n", waString);
    wprintf(L"int = %d\n", iInteger);
    wprintf(L"%d arguments read.\n", iSize);

    // Keep the window open until "Enter" is pressed
    getwchar();
    return 0;
}

Output

swscanf() Output
 

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