Got this error after running through most of the files. Then I found what I thought was a fairly egress error; fixed it; and now the code runs through less than half the files.
Code:
#include <stdio.h>
#include "ID.h"
int main(int argc, const char * argv[]) {
int i;
stock_index *indx;
indx = (stock_index *)calloc(num_of_indices, sizeof(stock_index));
listp = open_symbol_list();
for (i = 0; i < num_of_indices; i++)
{
datap = get_index_and_open(listp);
read_data_to_struct(datap, i, &indx[i]);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "math.h"
#define list_of_indices "/Users/douglasbrenner/ANDY/DATA/data_files/files.txt"
#define home "/Users/douglasbrenner/ANDY/DATA/data_files/"
#define results "/Users/douglasbrenner/ANDY/arisk/results/"
#define days_of_data 60000
#define num_of_indices 1466
#define last_date "20161007"
#define first_date "20061006"
#define true 1
#define false 0
#define PER_SHARE_FEE 0.0
#define PER_TRADE_FEE 0
#define initial_investment 500000
#define nextday 1
#define days_of_risk 0
FILE *listp, *datap;
typedef struct equity
{
char name[20][days_of_data];
char date[14][days_of_data];
float close[days_of_data];
int num[days_of_data];
} stock_index;
typedef struct hi_low_vol
{
char name[20];
float high;
float low;
float val;
} stock_index_paras;
void read_data_to_struct(FILE *datap, int i, stock_index indx[i] )
{
int j;
char *line, *junk;
line = (char*)calloc(75,sizeof(char));
junk = (char*)calloc(10,sizeof(char));
j = 0;
// fscanf(datap,"%s",line);
//fgets(line,75,datap); //read first line
do
{
fscanf(datap,"%s",line);
// printf("%s\n",line);
strcpy(indx[i].name[j],strtok(line,","));//symbol
strcpy(junk,strtok(NULL,","));
strcpy(indx[i].date[j],strtok(NULL,",")); //FAILS HERE
// printf("%s %s \n",indx[i].name[j],indx[i].date[j] );
}
while( (strcmp(first_date,indx[i].date[j++]))!= 0);
printf(" %s %s\n",indx[i].name[j-1],indx[i].date[j-1] );
fclose(datap);
free(line);
free(junk);
return;
}
FILE * open_symbol_list()
{
if ((listp = fopen(list_of_indices,"r")) == NULL)
{
printf("Couldn't open list of indices\n" );
exit(0);
}
else
printf("Opened list of indices\n");
return(listp);
}
FILE * get_index_and_open(FILE * listp)
{
char *filename,*path;
FILE *datap;
filename = (char *) calloc(75,sizeof(char));
path = (char *) calloc(75,sizeof(char));
if ( (fscanf(listp,"%s",filename)) != 0)
{
strcpy(path,home);
strcat(path,filename);
if ((datap = fopen(path,"r")) == NULL)
{
printf("Couldn't open index file\n" );
exit(0);
}
else
{ printf("opened data file %s\n", filename);
fscanf(datap,"%s",filename); //read header line
//printf("%s\n",filename);
}
}
free (filename);
free (path);
return (datap);
}
/[code]