C Standard Libraries C++

sscanf()

Declaration

int sscanf(const char* kcpBuffer, const char* kcpFormatString, ...);

Description

This function reads and assigns formatted data from the string "kcpBuffer." The function returns the number of fields successfully assigned. If no fields were read or an error occurred, the function returns EOF.

Example

#include <cstdio>

int main()
{
    char caBuffer[] = "Copyright 2009 XoaX";
    // Read from the buffer
    char caCopyright[20];
    int iYear = 0;
    char caXoaX[20];
    sscanf(caBuffer, "%s %i %s", caCopyright, &iYear, caXoaX);

    // Output the read contents
    printf("Read: %s %i %s\n", caCopyright, iYear, caXoaX);

    return 0;
}

Output

sscanf() Output
 

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