Initializing an array after declaration

前端 未结 4 1389
自闭症患者
自闭症患者 2021-01-27 01:56

gcc 4.4.3 c89

I have the following code as a sample of what I am trying to do. I don\'t know the actual size of the array, until I enter the function. However, I don\'t

4条回答
  •  广开言路
    2021-01-27 02:24

    Make it dynamic:

    char **g_device_names;
    int g_num_devices;
    
    void fill_devices(size_t num_devices) {
        g_device_names = malloc(sizeof(char*) * num_devices);
        g_num_devices = num_devices;
        ...
    }
    

提交回复
热议问题