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 fgets

    C fgets() function is implemented in file-related programs for reading strings from any particular file. It gets the strings 1 line each time. This tutorial guides you on how to use the fgets() function in the C program.

    Syntax:

    char *fgets(char *str, int n, FILE *stream)

    Example:

    void main(void)
    {
        FILE* fileName;
        char ch[100];
        fileName = fopen("anything.txt", "r");
        printf("%s", fgets(ch, 50, fileName));
        fclose(fileName);
    }
    • On success, the function returns the same str parameter
    • C fgets() function returns a NULL pointer in case of failure.


    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.