Reading from file into structs..
Dear All,
After spending a great deal of time searching previous posts, I am still stuck with the following. Essentially I am trying to open and read from a file, storing the file data into a struct. Please see below:
here is my struct declared in my header file....
Code:
typedef struct {
int carsSold[MAX_BRANDS];
float carSaleValue;
}CarSales;
now i need to open an existing file and read the data into the above struct. the file data is in the following format ...
20,20100.20
15,15100.50
.. and here is my code so far (not very far i know!)....
Code:
FILE *fptr = NULL;
CarSales s;
int j;
/* open car sales file for reading */
fptr = fopen("Sales.txt", "r");
/* check to see if car sales file opened succesfully */
if(fptr == NULL){
printf("Failed to open car sales file for reading.\n");
}
what would the best method be to read the file data and store it in the struct? any ideas would be appreciated!
cheers,
dankas