Question: Write a C code that stores dates in an array of structures and implements the basic functionality provided below. The structure type youll define has

Write a C code that stores dates in an array of structures and implements the basic functionality provided below. The structure type youll define has a tag name Time_info and it stores day, month and year information. Implement 3 functions:

- insert: takes a Time_info variable and inserts it into an array of Time_info structures at the specified index. On success it returns 1 and on fail (invalid index) it returns 0.

- find: Takes an array of Time_info structures, a day, a month and a year and looks for a Time_info structure with the specified day, month and the year. It returns a pointer to Time_info structure if its found in the array, NULL otherwise.

- print: takes a Time_info variable and print its contents.

In main function

create an array of Time_info structures that stores valid random dates between 01.01.1990 - 31.12.2021. You can decide on the size of this array as you wish.

Create a Time_info variable and initialize it with a date you choose and test your functions with it. If inserting a Time_info variable into the array fails due to an invalid index print the message insertion failed on standard error stream.

If a Time_info variable is found in the array, print its index on the screen along with its contents using the print function you wrote.

If a Time_info variable is NOT found in the array, print the message Birthday not found on the screen.

Heres a sample output for the last 3 bullets listed above

Write a C code that stores dates in an array of structures

Charubyy@arch-zenbook 14 exams]$ clang timestamps.c -o timestamps Charubyy@arch-zenbook 14 exams]$ ./timestamps insert failed... [harubyy@arch-zenbook 14 exams]$ clang timestamps.c -o timestamps Charubyy@arch-zenbook 14 exams]$ ./timestamps Found at index 4 day: 15, month: 3, year: 1990 Charubyu@arch-zenbook 14 exams]$ clang timestamps.c -o timestamps Charubyy@arch-zenbook 14 exams]$ ./timestamps Birthday not found Charubyy@arch-zenbook 14 exams]$ 0

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!