Read file contents with unknown size

后端 未结 3 343
小鲜肉
小鲜肉 2021-01-14 11:44

I want to process the contents of a config file. The config file could be any size. I am getting a Bus Error, after the program hangs, when I run the following code:

3条回答
  •  失恋的感觉
    2021-01-14 11:54

    You can allocate memory with malloc:

    buffer = malloc(number_of_bytes_to_allocate);
    if(buffer == NULL) {
        // error allocating memory
    }
    

    free when you're done with it!

    free(buffer);
    

提交回复
热议问题