Question: Program in C: File IO: I) Write a function that opens a file named test and prints some random text to the file. II) Write
Program in C: File IO:
I) Write a function that opens a file named test and prints some random text to the file.
II) Write a program that opens a file name test and prints the content of the file to screen.
III) Write a function void savePerson(char fileName[], Person p)that opens a file named fileName and prints the person to the file, as follows:
Name age score // Ex. John 25 95
IV) Write a function Person loadPerson(char fileName[]) that reads the file created by savePerson and returns a Person with the attributes in the file.
The function prototypes and a sample main are provided below:
Person createPerson(char name[],int age,double score);
void printPerson(Person p);
void savePerson(char fileName[], Person p);
Person loadPerson(char fileName[]);
void main(){
Person p = createPerson("John",25,95);
char file[] = "testPerson";
savePerson(file,p); //check file manually
Person p2 = loadPerson(file);
printPerson(p2);
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
