I have still problem with a Segmentation fault in the C code. When I call the function current_live_read(ainpath);
for the 8th time I'm getting the error: No source available for "_int_malloc() at 0x25be2"
The main function looks like this:
void current_read(void)
{
system(AINinit);
char *ainpath;
ainpath=init_current();
int *current;
float avgcurr=0;
float allcurr=0;
int i=0;
while(1)
{
//sleep(1);
i++;
current=current_live_read(ainpath);
allcurr=allcurr+*current;
avgcurr=allcurr/i;
printf("\n Current: %d AVG: %f", *current, avgcurr);
//free(current);
}
}
The current_live_read(ainpath);
is like that:
int *current_live_read(char *ainpath)
{
//ainpath=init_current();
int curr;
FILE *file = fopen(ainpath, "r");
//free(ainpath);
if(!file)
{
printf("Error opening file: %s\n", strerror(errno));
}
else
{
fscanf(file, "%4d", curr);
fclose(file);
//*current=curr;
}
free(file);
return curr;
}
I know that something could be wrong with the pointers, but I don't know which one and what I can do about it.