Results 1 to 5 of 5

Thread: How can I use the mbtowc()

  1. #1
    Join Date
    Jan 2010
    Posts
    22

    How can I use the mbtowc()

    Hi, I am working in the PQR company. I am working there as a C programmer. I have the good knowledge of the C language. But I do not know about the mbtowc() function. So, I would like to know about the mbtowc() function. I would also like to know about the how can I use the mbtowc() function in the C program and what is the actual use of the mbtowc() function. Thus, Can anyone has the solution to my query? Post me a better solutions as early as you can.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    mbtowc()

    Hello, A character of single multibyte pointed to by pointer parameter into the character code that can be corresponds to it, can be converted by the mbtowc() function. For all of null character can be zero. The code can be stored in the object that is pointed to by pwc, If pwc can not be a NULL pointer and the multibyte character can not be valid. The mbtowc() function could not examined more than M_CR_MX bytes.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,394

    How can I use the mbtowc()

    The mbtowc() function can returns the following, If t can not be a NULL pointer :
    1. If the next fewer or n bytes form a valid character of multibyte, then returns the number of bytes that can comprise the character of mutibyte.
    2. If the next n bytes can not form a valid character of multibyte returns -1 .
    3. If t can points to the null character, returns the zero.
    The mbtowc() function can return the zero if encoding of character of mutibyte can not be state dependent and otherwise returns the nonzero, If t can be a NULL pointer.

  4. #4
    Join Date
    May 2008
    Posts
    2,393

    Program : mbtowc()

    #include<stdio.h>
    #include<stdlib.h>
    int lnt, tmp;
    char strdt [6] = "n";
    wchr_t m_ary[6];
    int main(void)
    {
    lnt = mblen(NULL, M_CR_MAX);
    lnt = mblen(strdt, M_CR_MAX);
    tmp = mbtowc(arr,strdt,lnt);
    m_ary[1] = L'\0';
    printf("wide character strdata: %ls\n", m_ary);
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,856

    Re: How can I use the mbtowc()

    #include <stdio.h>
    #include <stdlib.h>
    void main()
    {
    char *w = "string";
    wchr_t wbfr[10];
    int j, ln;
    printf( "Character encodings do %shave " "state-dependent \nencoding.\n",( mbtowc( wbuffer, NULL, 0 ) )? "" : "not " );
    ln = mbtowc( wbfr, wc, 2 );
    wbfr[ln] = '\0';
    printf( "%s(%d)\n", wc, ln );
    for( j = 0; j < ln; j++ )
    printf( "/%4.4x", wbfr[j] );
    printf( "\n" );
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •