Concept

How does lsearch() search an array and insert a missing element?

ComputerScienceOne / Searching

"In the same library, there is another linear search function:\n\nvoid *lsearch(const void *key, void *base, size_t *nmemb, size_t size, int(*compar)(const void *, const void *));\n\nIt differs in that if it does not find a matching element, it still returns NULL but also attempts to insert the element being searched for at the end of the array. The function will assume there is enough room at the end of the array to accommodate the inserted element (if not, the behavior is undefined). This behavior is hinted at by the fact that base is not const. Moreover, nmemb is passed by reference. If the function inserts the element, it will also increment nmemb variable to reflect this new element. It is your responsibility to ensure that there is enough valid memory to accommodate any inserts when using lsearch()."

Related Ideas

How does lsearch() search an array and insert a missing element? | ComputerScienceOne | Bifalgorithm | Bifalgorithm