/* This C program reads a file and prints the contents */
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
/* prototypes */
void dump_names(char name[], int age);
/* file pointer */
int main()
{
char name[10];
int age;
input_ptr = fopen("a:\\myfile", "r");
if (input_ptr == NULL)
{printf ("error opening file.\n"); }
else
{
clrscr();
printf("\t\t\t\t Name Age\n");
while (fscanf(input_ptr, "%s %d ", name, &age) != EOF)
{
dump_names(name, age);
}
}
fclose(input_ptr);
printf("\n\npress any key to end program");
getch();
return 0; /* end of main */
}
void dump_names(char name[], int age)
{
printf("\n\t\t\t data - %10s %5d",name, age);
return;
}