I get a can't be freed because it wasn't allocated at free(day)
Code:
typedefstruct sauce
{
char date[14];
char name[20];
float sauce;
float open;
int signal;
int index;
float value;
} pesto;
void convert_dates(pesto * signal, int days)
{
char *day, *month, *year;
char *new_day, *new_month, *new_date;
int i, j;
// printf("here again\n");
new_day = (char *)calloc(3, sizeof (char));
new_month = (char *)calloc(3, sizeof (char));
new_date = (char *)calloc(9, sizeof (char));
day = (char *)calloc(3, sizeof (char));
month = (char *)calloc(3, sizeof (char));
year = (char *)calloc(11, sizeof (char));
for(j = 0, i = days - 1062; i < days ; i++, j++)
{
// printf("here i %d %s %s\n", i,signal[i].date, month);
month = strtok(signal[i].date,"/");
if (atoi(month) < 10)
{
strcpy(new_month,"0");
strcat(new_month,month);
}
else
strcpy(new_month,month);
day = strtok(NULL,"/");
// printf("day %s\n", day);
if (atoi(day) < 10)
{
strcpy(new_day,"0");
strcat(new_day,day);
}
else
strcpy(new_day,day);
// printf("new_day %d %s\n",i, new_day);
year = strtok(NULL,"/");
if ( (atoi(year) > 0 ) && (atoi(year)< 90) )
strcpy(new_date,"20");
else
strcpy(new_date,"19");
strcat(new_date, year);
strcat(new_date, new_month);
strcat(new_date, new_day);
strcpy(signal[i - 3300].date,new_date);
signal[j].signal = signal[i].signal;
// printf("new_date %s %d %d \n", new_date,j, signal[j].signal);
}
free(new_day);
free(new_month);
free(new_date);
free(day);
free(month);
free(year);
return;
}
Last edited: