RSieve icon

Sheet number divider

RSieve | PRO | 12/20/17 02:50:33 PM UTC | 0 ⭐ | 240 👁️ | Never ⏰ | []
C |

1.48 KB

|

None

|

0 👍

/

0 👎

/**
 *  Useless stuff.
 *  I was bored and I wanted to know the number of sheets of paper that were
 *  were going to be printed to buy the correct folder.
 *  You can actually change it to fit your needs. With num page you define
 *  the number of slides you are going to put in a single side. I usually use
 *  8 per side and that's my way.
 *  In the file.txt write all the number of slides for each pdfs and it will
 *  print to a txt file the number of sheets you will be needed.
 *  Enjoy lazy uselessness
 * 
 *  @author Riccardo Sieve
 */
 
#include<stdio.h>
#include<stdlib.h>
 
#define NUM_PAGE 8
 
typedef enum {FALSE, TRUE} boolean;
 
boolean is_divisible(int , int );
boolean is_even(int);
 
int main() {
 
    int num=0, sum=0;
    FILE *fin, *fout;
 
    if((fin = fopen("file.txt", "r")) == NULL) {
        fprintf(stderr, "Error in opening the file");
        exit(1);
    }
 
    if((fout = fopen("out.txt", "w")) == NULL) {
        fprintf(stderr, "Error with output file");
        exit(2);
    }
 
    while(fscanf(fin, "%d", &num) != EOF) {
        if(is_divisible(num, NUM_PAGE))
            num /= NUM_PAGE;
        else
            num /= NUM_PAGE + 1;
 
        if(is_even(num))
            sum += (num / 2);
        else
            sum += (num / 2) + 1;
    }
 
    fprintf(fout, "%d", sum);
 
    return 0;
}
 
boolean is_divisible(int a, int b) {
    return (a % b == 0);
}
 
boolean is_even(int a) {
    return is_divisible(a, 2);
}

Comments