Question: 1. Modify the program so that it will read student names from a data file and store them into unixClass array. Please use studentNames.txt as

1. Modify the program so that it will read student names from a data file and store them into unixClass array. Please use studentNames.txt as your input file.

2. Use rand function to generate a random age, ranging from 17 to 36 for each student in unixClass.

3. Change the constant SIZE to 500. This will be large enough to store all students from the input file. Remember 500 is defined as the original array size. It is not the actual student count. You will need to keep track the student count while getting input from the data file.

The code is below

#include typedef struct { char name[40]; int age; } student; #define SIZE 2 void getData(student[], int); void printData(student[], int); int main() { student unixClass[SIZE]; getData(unixClass, SIZE); printData(unixClass, SIZE); return 0; } void getData(student anyAry[], int anySz) { int i, c; for (i = 0; i < anySz; i++) { printf("Enter a name: "); gets(anyAry[i].name); printf("Enter age: "); scanf("%d", &anyAry[i].age); c=getchar(); } }

void printData(student anyAry[], int anySz) { int i; for (i = 0; i < anySz; i++) { printf("The name of student %d is %s ", i+1, anyAry[i].name); printf("The age of student %d is %d years old ", i+1, anyAry[i].age); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!