home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 241,964 of 243,242   
   Michael Sanders to Richard Tobin   
   Re: Unicode...   
   14 Nov 25 23:51:38   
   
   From: porkchop@invalid.foo   
      
   On Fri, 14 Nov 2025 23:23:15 -0000 (UTC), Richard Tobin wrote:   
      
   > In article <10f85f9$33pck$1@dont-email.me>,   
   > Michael Sanders   wrote:   
   >>    const char *s = "élan";   
   >>    printf("string:     %s\n", s);   
   >>    printf("strlen:     %d\n", strlen(s)); // 4   
   >>    printf("utf8_width: %d\n", utf8_width(s)); //5   
   >   
   > I think you have those numbers the wrong way round.   
      
   I'm working on it Richard, little by little...   
      
   Just discovered %z too.   
      
   #include    
   #include    
      
   static int is_ascii_7bit(const char *s) {   
       const unsigned char *p = (const unsigned char *)s;   
       while (*p) {   
           if (*p >= 0x80) return 0;  // reject immediately   
           p++;   
       }   
       return 1;   
   }   
      
   static size_t ascii_width(const char *s) { return strlen(s); }   
      
   int main(void) {   
       const char *s = "élan"; // NOT 7-bit clean   
       printf("string:      %s\n", s);   
       printf("strlen:      %zu\n", strlen(s));   
       printf("7bit OK?:    %s\n", is_ascii_7bit(s) ? "YES" : "NO");   
       printf("ascii_width: %zu\n", ascii_width(s));   
       return 0;   
   }   
      
   --   
   :wq   
   Mike Sanders   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca