C program to read a file containing numbers, and then print ones divisible by 3 to another file
The easiest way to make this more compact is to write a function to handle opening a file and just pass in the name and mode you want. Something like this:

FILE* open_file_or_exit(const char* filename, const char* mode)
{
    FILE* fileHandle = NULL;
    if((fileHandle = fopen(filename, mode)) == NULL){
        perror(filename);
        exit(EXIT_FAILURE);
    }
    return fileHandle;
}


Your main() then becomes:

int main(void){
    FILE *in_file = open_file_or_exit("total", "r");
    FILE *out_file_divis = open_file_or_exit("divis", "w');
    FILE *out_file_remain = open_file_or_exit("remain", "w");
    // ... rest of main ...
}


Any time you find yourself repeating the same few lines of code, that's a good sign that it should go into a function.