Home > Back-end >  I'm getting an error in norminette because my code is more than 25 lines long
I'm getting an error in norminette because my code is more than 25 lines long

Time:01-10

void    set_default(t_fdf *data, char **av)
{
    read_map(data, av[1]); *-> dont care this func*
    if (data->map_size <= 500)
    {
        data->window_x = 960;
        data->window_y = 540;
        data->zoom = 30;
        data->depth = 2;
    }
    else if (data->map_size <= 3000)
    {
        data->window_x = 1280;
        data->window_y = 720;
        data->zoom = 20;
        data->depth = 15;
    }
    else if (data->map_size <= 5000)
    {
        data->window_x = 1366;
        data->window_y = 768;
        data->zoom = 20;
        data->depth = 10;
    }
    else if (data->map_size <= 10000)
    {
        data->window_x = 1600;
        data->window_y = 900;
        data->zoom = 10;
        data->depth = 5;
    }
    else
    {
        data->window_x = 1720;
        data->window_y = 900;
        data->zoom = 5;
        data->depth = 4;
    }
}

i wanna short this code. I can create an extra function. but this function is forbidden to take more than 4 parameters. I need to place the values ​​that change according to the size of the map into my data.

CodePudding user response:

Perhaps, define an array of struct of type t_fdf:

struct t_fdf data[] = {
    {960, 540, 30, 20},
    {1280, 720, 20, 15},
    {1366, 786, 20, 10},
    {1600, 900, 10, 5},
    {1720, 900, 5, 4}
};

Then you can assign individual members of the array to the pointer. Much like how the GNU's getopt_long function works.

You might benefit from some more information about the function here: https://linux.die.net/man/3/getopt_long

  • Related