home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / r_la4_02 / writef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-07  |  1.0 KB  |  30 lines

  1. /* WRITEF.C - From page 441 of "Microsoft C Programming for     */
  2. /* the IBM" by Robert Lafore. This program writes formatted     */
  3. /* data to a file. To use, enter data at prompt as follows:     */
  4. /*   Bond 007 74.5 <return>.   To exit after entering desired   */
  5. /* number of lines, enter at prompt:   x 0 0 <return>.          */
  6. /* This program will not work correctly if the DOS type comm-   */
  7. /* and is used to read it. To read the file, use READF.C, also  */
  8. /* on this disk. The file WRITEF_A.C on this disk can be read   */
  9. /* with the DOS type command.                                   */
  10. /****************************************************************/
  11.  
  12. #include <stdio.h>
  13.  
  14. main()
  15. {
  16. FILE *fptr;
  17. char name[40];
  18. int code;
  19. float height;
  20.  
  21.    fptr = fopen("c:textfile.txt", "w");
  22.    do {
  23.       printf("Type name, code number, and height: ");
  24.       scanf("%s %d %f", name, &code, &height);
  25.       fprintf(fptr, "%s %d %f", name, code, height);
  26.    } while(strlen(name) > 1);              /* no name given ? */
  27.    fclose(fptr);
  28. }
  29.  
  30.