home *** CD-ROM | disk | FTP | other *** search
- /*
- * W R I T E
- *
- * Write a line of text to a file.
- */
-
- #include <stdio.h>
-
- #define MAXPATH 64
-
- int
- main(void)
- {
- int ch; /* input character */
- FILE *fp; /* file pointer */
- char pathname[MAXPATH]; /* filename 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 characters from the keyboard up to a newline
- * character, then write the line to the specified file.
- */
- while ((ch = getchar()) != '\n')
- fputc(ch, fp);
- fputc('\n', fp); /* terminate the line */
-
- /*
- * Close the file.
- */
- fclose(fp);
-
- return (0);
- }
-