Problem with strlen() and UTF8 characters

posted by softweb on 2009-06-18 00:00:00
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int main(){
        char *s;
        s = (char *) malloc(sizeof(char)*100);
 
        scanf("%s", s);
        printf("Len: %d\n", strlen(s));
 
        return 0;
}
 
I think this code is correct, but when I digit UTF8 characters like (òàùèì), strlen returns wrong length.
What could i do to fix it?
Thank you
dail avatar
dail
12
You have to use wcslen() function.
 
#include <wchar.h>
size_t wcslen(const wchar_t *ws);
 
It returns wide-character string length.
Bye.
49 answers - 0 questions
+ 2  Positive        Negative

softweb avatar
softweb
2
Thank you
Bye
7 answers - 7 questions
  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)