The function fgets can be used to read a line of input from a file. The function receives as input a buffer that will be used to read the data, the size of the buffer, and a pointer to the FILE structure representing the file.

The following program shows an example of use for the fgets function.

#include <stdio.h>
#include <string.h>

int main()
        char s[5];
        fgets(s, sizeof(s), stdin);
        printf("input is %s", s);
        return 0;
Article created on 2008-08-19 22:06:00

Post a comment