Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C fscanf

    C fscanf() function reads formatted input from a file. This function is implemented in file-related programs for reading formatted data from any file specified in the program. This tutorial guides you on how to use the fscanf() function in the C program.

    Syntax:

    int fscanf(FILE *stream, const char *format, ...)

    Its returns the number of variables that are assigned values or EOF if no assignments could be made.

    Example:

    int main()
    {
        char str1[10], str2[10];
        int yr;
        FILE* fileName;
        fileName = fopen("anything.txt", "w+");
        fputs("Welcome to", fileName);
        rewind(fileName);
        fscanf(fileName, "%s %s %d", str1, str2, &yr);
        printf("----------------------------------------------- \n");
        printf("1st word %s \t", str1);
        printf("2nd word  %s \t", str2);
        printf("Year-Name  %d \t", yr);
        fclose(fileName);
        return (0);
    }


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.