store known key/value pairs in c

后端 未结 4 411
孤独总比滥情好
孤独总比滥情好 2020-12-30 05:21

I\'m currently learning c. I\'m writing a web server as an exercise.
Now i have to store the status codes and reason phrases.

What is the best way to store those

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 05:39

    I would use a sorted array.

    You can define the array in any order, and sort it at run-time (once) with the qsort() function. Then you can do binary searches using bsearch(). The total number of response codes is small, a binary search will be very fast.

    This has the advantage of not needing any external code, for something simple like this.

提交回复
热议问题