< C

UTF-8 kódolású karaktersorozatok hosszának vizsgálata

ukarhossz.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iconv.h>
 
#include "str.h"
 
int wstrlen(char *in)
{
 
    iconv_t iconv_cd;
    char *input, *output;
    char *input_start, *output_start;
    size_t input_len = 255, output_len = 255;
 
    input = (char*) malloc(255*sizeof(char));
    output = (char*) malloc(255*sizeof(char));
 
    input_start = input;
    output_start = output;
 
    input = in;
 
    iconv_cd = iconv_open("ISO8859-2", "UTF-8");
    iconv(iconv_cd, &input, &input_len, &output, &output_len);
    iconv_close(iconv_cd);
 
    return(strlen(output_start));
 
}