thanks for the comments.... here is my latest code (note that the structs are slightly different but you will get the idea)...
structs....
Code:
/* declare structure for date */
typedef struct date {
int dd; /* day */
int mm; /* month */
int yy; /* year */
}Date;
/* declare structure for sales log */
typedef struct {
Date dt;
int canSold[MAX_BRANDS];
double valueOfSale;
}LogType;
file to read has format of:
22/10/01,20,2.25
23/10/01,20,2.50
latest code to try and read file data into struct is:
in main i call function to load struct:
Code:
/* load sales data */
for (i = 0; i < MAX_LOG; i++){
salesInfo[i] = load_sales(dt, canSold, valueOfSale, i, f2);
}
here is the load function:
Code:
LogType load_sales(Date dt, int canSold, double valueOfSale, int i, char f2[])
{
LogType l;
char filename2[MAX_PASS + 1];
FILE *fptr2 = NULL;
strcpy(filename2, f2);
printf("%s\n", filename2);
/* open sales file for reading */
fptr2 = fopen(filename2, "r");
if(fptr2 == NULL){
printf("Failed to open file for reading.\n");
}
/* load data into struct */
fscanf(fptr2, "%d/%d/%d,%d,%f", &l[i].dt.dd, &l[i].dt.mm, &l[i].dt.yy, &l[i].canSold, &l[i].valueOfSale);
}
NB: that f2 is simply the filename that is passed to the load function.
I am getting the error at line leading with fscanf as mentioned just above (below /* load data into struct */).
I appreciate all the help!
dankas