how to solve segmentation fault
#include <stdio.h>
#include <stdlib.h>


// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *file, char *required){
    int result = 1;
    int i;
    for (i = 0; i < 9 ; i++){
    	if (file[i] != required[i] && required[i] != '-'){
            result = 0;
        }
    }
    return result;
}


int main(int argc, char** argv) {
    if (!(argc == 2 || argc == 3)) {
        fprintf(stderr, "USAGE: count_large size [permissions]\n");
        return 1;
    }

    int count = 0;

    // TODO: Process command line arguments.
    long size = strtol(argv[1], NULL, 10);
    // TODO: Call check_permissions as part of your solution to count the files to
    // compute and print the correct value.
    char file_permission[30];
    int file_size;
    scanf("%[^\n]s", file_permission);

    while (scanf("%s %*d %*s %*s %d %*[^\n]", file_permission, &file_size) == 2){
        printf("file permissions is %s\n", file_permission);
        printf("file size is %d\n", file_size);
        if (argc == 2 
            && file_size > size 
            && file_permission[0] != 'd'
            ){
                count++ ;
            printf("%s", "first if finished");
            } else {
                char *required = &argv[2][0];
                if (file_size > size 
                    && check_permissions(&file_permission[1], required)
                    && *file_permission != 'd'){
                count++;
            }
        }
    }
printf("%d\n", count);
return 0;
}


