Question: Hello, I am working on a fillArray function. The function takes a Stock struct and reads stocks from a .txt file and adds them in
Hello, I am working on a fillArray function. The function takes a Stock struct and reads stocks from a .txt file and adds them in a stock array, and then I can sort them and do whatever I wanted with them after that. I have some code wrote but I am unsure if I am on the right path or if it is easier then what I am making it to be? Here are the images of what I do have right now

The stocks,txt file (already have a method for opening it) just need to read them out of the file and add to the stocks array

Let me know if you can help or if you need any more information. Thank you!
#ifndef LAB9_H #define LAB9_H #include ... struct stock char symbol[10]; char name (100); double price; typedef struct stock Stock; * Fills the array with Stocks. Reading from the file. Note the file * contains 3 lines per Stock. You are guaranteed there are 1 to 10 Stocks in the file * and the file is well formed * @param array Representing the array of Stock references * @parma fin Representing an open and valid FILE pointer * @return int Representing the actual number of Stocks int fillArray(Stock array(), FILE * fin); int fillArray (Stock array[], FILE * fin) { int total = readstocks (fin); if(total == 0) { return -1; array - (Stock*)calloc(total, sizeof(struct stock)); int found, i=0, tempInt; while( ! feof(fin)) { for (i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
