I have a function that is called within a loop. The array in this function is 382 in length. The output of the program is usually no more than about 50 characters.
My problem is that after the function has looped approx 21 times the app seg faults. Just as a test I increased the array to 4096 from 382. The app now seg faults after 235 loops.
Code:
void Func_Get_Details()
{
char temp[MAX_DIR_LENGTH] = {0x0};
char t[30] = {0x0};
char tt[2] = {0x0};
int hours = 0;
int minutes = 0;
int seconds = 0;
file_read = popen("cat /home/text.txt","r");
while(fgets(temp,sizeof (temp),file_read))
delay = atoi(temp);
pclose(file_read);
if(delay < 15)
{
delay = 15;
}
if(delay > 600)
{
delay = 600;
}
file_read = popen("cat /home/text2.txt","r");
while(fgets(temp,sizeof temp,file_read))
strcat (img_main, temp);
pclose(file_read);
time_t s;
time(&s);
sprintf(t,"%s",ctime(&s));
strncpy(tt, t + 11, 12);
tt[2] = '\0';
hours = atoi(tt);
strncpy(tt, t + 14, 15);
tt[2] = '\0';
minutes = atoi(tt);
strncpy(tt, t + 17, 18);
tt[2] = '\0';
seconds = atoi(tt);
printf("Seconds %i\n", seconds);
printf("%i", hours);
printf("%i", minutes);
printf("%i\n", seconds);
change_time = (hours * 3600) + (minutes * 60) + seconds;
printf("number of seconds since midnight %i", change_time);
printf("\nTemp variable is %s: \n",temp);
}