Question: ----------C PROGRAMMING---------- Bonus: Load and Display Elements From File (elements.c) Write a program that reads information about a subset of the elements from the periodic

----------C PROGRAMMING----------

Bonus: Load and Display Elements From File (elements.c) Write a program that reads information about a subset of the elements from the periodic table of elements into an array of structures and prints out this array of structures to the screen in a well formatted way. The element structure (name it as element_t) should have the following components: element name (String), atomic number (int) and atomic mass (double). Implement the following functions: element_t * loadElements(char *fileName, int *noOfElements); element_t * createElementArray(char *name, int atomicNumber, double atomicMass); void printElements(element_t *elementArray, int noOfElements);

loadElements: This function opens a text file (First argument) containing information about the elements. In the text file, each element is stored in a different line and element components are separated by white space. See the sample input file "elementFacts.txt". First, the function will count the number of lines in the file and create an element array with a size equivalent to the number of lines. Then it will read each line from the file, create an element structure and store it in the array by using the createElementArray function. Also the function updates the number of element count via the second argument pointer variable. Finally, the function returns a pointer to this array.

printElements: This function takes an element array as the first argument and number of element count (in the array) as the second argument. Then it displays the elements from the array. The main function should have the following four statements: char fileName[] = "elementFacts.txt''; int noOfElements = 0; element_t *elements = loadElements(fileName, &noOfElements); printElements(elements, noOfElements);

Sample Output: Element: Hydrogen Atomic Number: 1 Atomic Mass: 1.007900

Element: Helium Atomic Number: 2 Atomic Mass: 4.002600

Element: Lithium Atomic Number: 3 Atomic Mass: 6.941000

Data Type Requirement: Element name is character string, atomic number is integer, atomic mass is double.

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!