C Programming

These are useful for reading and writing entire lines of data to/from a file. If buffer is a pointer to a character array and n is the maximum number of characters to be stored, then

	fgets (buffer, n, input_file);

will read an entire line of text (max chars = n) into buffer until the newline character or n=max, whichever occurs first. The function places a NULL character after the last character in the buffer. The function will be equal to a NULL if no more data exists.

	fputs (buffer, output_file);

writes the characters in buffer until a NULL is found. The NULL character is not written to the output_file.

NOTE: fgets does not store the newline into the buffer, fputs will append a newline to the line written to the output file.

ęCopyright B Brown. 1984-1999. All rights reserved.