In C how to get number of items in array of pointers to char strings

后端 未结 5 1081
别跟我提以往
别跟我提以往 2020-12-11 06:03

I want to implement the following function to print the contents of several char strings which are referenced through a pointer array. How can I determine how

5条回答
  •  猫巷女王i
    2020-12-11 06:05

    There is no built-in way to do this as C does not track the number of elements in an array for you like this.

    You have a couple of options:

    1. Pass the number of items in the array.
    2. Set the last item to NULL so the code knows when it's reached the end. (This is kind of how C strings are handled.)
    3. Otherwise modify your data structures to track the number of items in the array.

提交回复
热议问题