#include <stdio.h>
#include <stdlib.h>


int check_permissions(char *filter, char *permission){
    for(int i = 0; i<9;i++){
        if (filter[i] != '-'){
            if(filter[i] != permission[i]){
                return 1;
            }
        }
    }
    return 0;
}

int main(int argc, char** argv) {
    if (!(argc == 2 || argc == 3)) {
        fprintf(stderr, "USAGE: count_large size [permissions]\n");
        return 1;
    }
    char line[101];
    char permission[9];
    int size;
    int num = 0;
    int min = strtol(argv[1], NULL, 10);
    fgets(line, 101, stdin);
    while(fscanf(stdin, "%s %*d %*s %*s %d %*[^\n]", permission, &size) == 2){
        if((size > min) && (permission[0] != 'd')){
            if(argc == 3){
                if(check_permissions(argv[2], permission + 1) == 0){
                    num ++;
                }
            }else{
                num ++;
            }
        }
    };

    printf("%d\n", num);

    return 0;
}

For this assignment only, you may assume the following:

The user will provide at most two command-line arguments. If they are provided, arguments will be the correct type and in the correct order. In other words, if only one command-line argument is present, it is an integer. If two are provided, the first is an integer and the second is the required permissions string.
The input listing contains only regular files and directories. (There are no links or other unusual file types.)
Names of things (filenames, usernames, group names, ...) will be at most 31 characters.
An integer is large enough to hold any file sizes for this assignment.
Filenames do not have spaces in them.
In general these are not valid assumptions - either in the real world or in later CSC209 assignments - but making them puts the focus of this assignment on basic C syntax and use of arrays, rather than command line parsing.

Command-line arguments and return codes
Assumption 1 above is particularly unrealistic for real C programs. We would normally want to have many different options and would design our programs to behave like other C tools where options can be specified in any order and grouped together. In the future, you will learn about the getopt library that makes processing command-line arguments easy. But for now, you are not expected to use getopt. Feel free to try it on your own, but for this assignment, you are not expected to use it.

For this program, the user might still forget command-line arguments altogether. When this happens, your program shouldn't crash. Instead you should print to standard error the message "USAGE: count_large size [permissions]" (followed by a single newline \n character), and return from main with return code 1. The starter code actually implements this behaviour for you already. Following the standard C conventions, main should return 0 when the program runs successfully.