Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions