When I need a big exit transition, I usually encapsulate the loops in a function and just use return, for example:
void read(FILE*[] infiles, int N)
{
for(;;) {
sum_a = 0;
for(i=0 ; i<N ;i++){
if(fscanf(infiles[i], "%d\n", &a) != 1){
return;
}
sum_a += a;
}
printf("%d\n", sum_a);
}
}
void cleanup(FILE*[] infiles, int N)
{
for(i=0 ; i<N ;i++)
fclose(infiles[i]);
}
read(infiles, N);
cleanup(infiles, N);
It also helps to read the code.
Lithy source
share