/* This C program creates a file */

 

#include <conio.h>

#include <stdio.h>

#include <ctype.h>

 

/* prototypes */

 

void get_input(char name[], int * age);

void write_record (char name[], int age);

 

/* file pointer */

 

FILE *output_ptr;

 

int main()

{

    char name[10];

    int  age;

    char answer;

 

    output_ptr = fopen("a:\\outfile", "w");

    if   (output_ptr == NULL)

         {

             printf ("error opening file.\n");

         }

    else

      { clrscr();

        do

         {

          get_input(name, &age);

          write_record (name, age);

 

          printf ("\n\t\t\t Enter another? ");

          scanf(" %c", &answer);

 

         } while (toupper(answer) == 'Y');

       }

    fclose(output_ptr);

    return 0;                 /*  end of main */

}

 

void get_input(char name[], int * age)

     {

         printf("\n\t\t\t Enter your name please ");

         scanf("%s", name);

 

         printf("\n\n\t\t\t How old are you? ");

         scanf("%d”, age);

        

         return;

    }

 

void write_record (char name[], int age)

{

      fprintf(output_ptr, " %-10s %3d\n", name, age);

      return;

 

}