From: ben@bsb.me.uk   
      
   Michael Sanders writes:   
      
   > On Fri, 21 Nov 2025 18:41:01 -0000 (UTC), Michael Sanders wrote:   
   >   
   >> So strspn, perfect for what I need!   
   >>   
   >> before:   
   >>   
   >> int ok = 1;   
   >>   
   >> if (strlen(colorSpec) == 4) {   
   >> for (int i = 0; i < 4; i++) {   
   >> char c = colorSpec[i];   
   >> if (c < '1' || c > '8') { ok = 0; break; }   
   >> }   
   >> } else ok = 0;   
   >>   
   >> after:   
   >>   
   >> strspn() returns the length of the leading substring   
   >> consisting ONLY of characters in the allowed set...   
   >>   
   >> if (strlen(colorSpec) != 4 && strspn(colorSpec, "12345678") = 4) FAIL;   
   >   
   > Actually is should be:   
   >   
   > if (strlen(colorSpec) != 4 || strspn(colorSpec, "12345678") != 4) FAIL;   
   >   
   > Excuse the extra posts, got excited.   
      
   Sorry, I read threads in order so commented on this in my earlier reply.   
      
   --   
   Ben.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|