Code:
/
typedef struct sauce
{
char date[10];
float sauce;
float open;
int index;
} pesto;
pesto * make_instrument(pesto *etf1, pesto *etf2, int numi, int numk)
{
int comp,i,k, l , m;
pesto *new_security;
for(i = 0, k = 0; i < numi || k < numk; )
{
while((comp = strncmp(etf1[i].date,etf2[k].date,8))!= 0)
{
l = 0; m = 0;
if (comp > 0)
{
k++;
}
elseif (comp < 0)
{
i++;
}
}
if (comp == 0)
{
i++;
k++;
}
}
return(new_security);
};
void test_system()
{
int i,j, k, l,num;
char **etf_list, *line, *file_name;
FILE *etfi, *etfj;
pesto *datai, *dataj , *instrument;
instrument = (pesto*)calloc(days_of_data, sizeof(*instrument));
datai = (pesto*)calloc(days_of_data, sizeof(*datai));
dataj = (pesto*)calloc(days_of_data, sizeof(*dataj));
line = (char*) calloc(200,sizeof(char));
file_name = (char*) calloc(200,sizeof(char));
etf_list = read_list_of_etfs();
for (i = 0; i < num_of_etfs-1; i++)
{
strcpy(file_name,home);
strcat(file_name, etf_list[i]);
if (( etfi = fopen(file_name, "r")) == NULL)
printf("Couldn't open %s\n", file_name);
else
printf("%s ", file_name);
fgets(line,200,etfi);
k = 0;
while ((fgets(line,200,etfi)) != NULL)
{
strtok(line,","); //symbol
strtok(NULL,","); //D
strcpy(datai[k].date,strtok(NULL,",")); //date
strtok(NULL,","); //000000
datai[k].open = atof(strtok(NULL,","));
datai[k].index = k;
k++;
}
for (j = i+1; j < num_of_etfs; j++)
{ l= 0;
strcpy(file_name,home);
strcat(file_name, etf_list[j]);
if (( etfj = fopen(file_name, "r")) == NULL)
printf("Couldn't open %s\n", file_name);
else
printf(" %s\n", file_name);
fgets(line,200,etfj);
while ((fgets(line,200,etfj)) != NULL)
{
strtok(line,","); //symbol
strtok(NULL,","); //D
strcpy(dataj[l].date,strtok(NULL,",")); //date
strtok(NULL,","); //000000
dataj[l].open = atof(strtok(NULL,","));
dataj[l].index = l;
l++;
}
instrument = make_instrument(datai,dataj, k, l);
//run_instrument
// store_result();
fclose(etfj);
};
fclose(etfi);
}
free(line);
free(instrument);
free(datai);
free(dataj);
return;
};
/
Test_system declares a variable pesto *instrument; and allocates memory instrument = (pesto*)calloc(days_of_data, sizeof(*instrument)); However when the codes gets to free(instrument); I get an error message that says the pointer wasn't allocated.
Help, please.
Last edited by a moderator: