home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_02.ZIP / WRITEF_A.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-07  |  1.1 KB  |  34 lines

  1. /* WRITEF_A.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 has been changed from what's in the book to     */
  7. /* make it work correctly. The book version, WRITEF.C is also   */
  8. /* on this disk to use in conjunction with READF.C              */
  9. /****************************************************************/
  10.  
  11. #include <stdio.h>
  12.  
  13. main()
  14. {
  15. FILE *fptr;
  16. char name[40];
  17. int code;
  18. float height;
  19. int count = 0;
  20.  
  21.    fptr = fopen("c:textfile.txt", "w");
  22.    while((strlen(name) > 1) || count == 0) { /* no name given ? */
  23.       count++;
  24.       printf("Type name, code number, and height: ");
  25.       scanf("%s %d %f", name, &code, &height);
  26.       if(strlen(name) > 1) {
  27.          fprintf(fptr, "%-10s %03d %f", name, code, height);
  28.          fprintf(fptr, "\n");
  29.       }
  30.    }
  31.    fclose(fptr);
  32. }
  33.  
  34.