Question: #include #include #include #include typedef struct { char name[40]; int age; } student; #define SIZE 500 int actual_size = 0; // global variable to store

 #include #include #include #include typedef struct { char name[40]; int age;

#include #include #include #include typedef struct { char name[40]; int age; } student; #define SIZE 500 int actual_size = 0; // global variable to store the number of students in the file void getData(student[], int); void printData(student[], int); int main() { student unixClass[SIZE]; getData(unixClass, SIZE); printData(unixClass, actual_size); // passing actual size as parameter to print only required student details return 0; } void getData(student anyAry[], int anySz) { FILE* file = fopen("studentNames.txt", "r"); // opening file to read char name[40];// string to store name int i = 0; // for counting the number of students and used as index srand(time(0)); // this ensures to generate different set of random numbers every time while (fgets(name, sizeof(name), file)) { // reading name line by line //printf("%s ", name); name[strlen(name) - 1] = '\0'; // to remove newline character which occurs in the last of name strcpy(anyAry[i].name, name); // update name of array anyAry[i].age = 17 + rand()%20; // generate integer between 17 to 36. {rand()%20 gives 0 to 19} i++; } actual_size = i; // update actual size fclose(file);//closing file }

void printData(student anyAry[], int anySz) { int i; for (i = 0; i Part III (30 pts) Add a function that will take the unixClass array and the student count as parameter. It will find out the count of each age and print the result. For example, your output from this function may as the following: Age Count

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!