Course Content
Programming in C
About Lesson

The standard library provides routines to read an input line and write a text string.

char *fgets(char *line, int maxline, FILE *fp);

fgets reads the next input line (including the newline) from file pointed by fp into the character array pointed by line, reading at most maxline – 1 characters. The resulting line will be null terminated (‘\0’). Normally fgets returns line; in case of end of file or error, it returns NULL.

int fputs(char *line, FILE *fp);

fputs writes a string (which need not have a newline) to file pointed by fp. It returns EOF in case of error, else 0.

The library functions gets and puts are similar to fgets and fputs, but they operate on stdin and stdout. gets deletes the terminal ‘\n’ and puts adds it.

Scroll to Top