c splitting a char* into an char**

后端 未结 4 907
孤城傲影
孤城傲影 2021-01-22 09:20

I\'m reading in a line from a file (char by char, using fgetc()), where all fields(firstname, lastname, ...) are seperated by an ;. What I now want to do is create

4条回答
  •  感情败类
    2021-01-22 09:29

    Yes, it's possible. Yes, you can treat it as a one dimensional array. Yes, the memory is contiguous.

    But you probably want:

    char ** fields = malloc(sizeof(char *) * numFields);
    

    Then you can do:

    // assuming `field` is a `char *`
    fields[i++] = field;
    

提交回复
热议问题