[Info-vax] ChatGPT solved it for me, again...
Arne Vajhøj
arne at vajhoej.dk
Tue Feb 21 14:20:50 EST 2023
On 2/21/2023 8:25 AM, Simon Clubley wrote:
> On 2023-02-20, Arne Vajhøj <arne at vajhoej.dk> wrote:
>> I still stand by my original assessment that I would not
>> have used strcspn for this. It seems weird to me to
>> search through the entire string in a way that can handle
>> multiple stop characters when one knows that there is
>> only one stop character and really are only interested
>> in the last char in the string.
>>
>
> This is exactly how I normally do it - look at the last character
> only and strip that if needed.
>
> Of course, strlen() still has to search through the string before
> it knows the length of it, so you don't save as much time as you
> might expect.
Yes - strlen will involve some sort of loop.
But strcspn will involve a loop inside a loop.
Although the loop over the reject set will
be very short in this case.
glibc use while with strchr inside.
BSD use for with a do while inside.
(links posted previously)
Arne
More information about the Info-vax
mailing list