// FileIO.cpp : Defines the entry point for the console application. // #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int age; int i; char name[50]; FILE *fptr; if (( fptr = fopen("datafile.dat", "w") ) == NULL) printf("Bad File or File Name\n\n"); else { for(i=1; i<= 5; i++) { printf("Enter the next person's name: "); scanf("%s", name); //Read name from screen printf("Enter the next person's age: "); scanf("%d", &age); //Read age from screen fprintf(fptr, "The age of %s is %d\n", name, age);//Write name and age to file } } fclose(fptr); return 0; }