/*
 * W R I T E _ 2
 *
 * Write line of text to a file. Terminate input by
 * pressing Enter on a blank line.
 */

#include <stdio.h>

#define MAXPATH 64
#define MAXLINE 256

int
main(void)
{
	int ch;                 /* input character */
	FILE *fp;               /* file pointer */
	char pathname[MAXPATH]; /* file name buffer */
	char line[MAXLINE];     /* line buffer */

	/*
	 * Prompt the user for a filename and read it.
	 */
	printf("Filename: ");
	gets(pathname);
	if (*pathname == '\0')  /* no name typed */
		return (0);

	/*
	 * Open the named file for writing.
	 */
	fp = fopen(pathname, "w");

	/*
	 * Read lines of text from the keyboard and write them to
	 * the specified file. Quit when an empty line is seen.
	 */
	while (1) {
		fgets(line, MAXLINE, stdin);
		if (line[0] == '\n')    /* empty line */
			break;
		fputs(line, fp);
	}

	/*
	 * Close the file.
	 */
	fclose(fp);

	return (0);
}
