Dynamically create an array of strings with malloc

前端 未结 4 2075
孤城傲影
孤城傲影 2020-11-28 05:23

I am trying to create an array of strings in C using malloc. The number of strings that the array will hold can change at run time, but the length of the string

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 06:13

    
    #define ID_LEN 5
    char **orderedIds;
    int i;
    int variableNumberOfElements = 5; /* Hard coded here */
    
    orderedIds = (char **)malloc(variableNumberOfElements * (ID_LEN + 1) * sizeof(char));
    
    ..
    
    

提交回复
热议问题