Click here to Skip to main content
15,881,803 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Unicode CString and fopen problem Pin
tagopi7-Apr-13 20:21
tagopi7-Apr-13 20:21 
GeneralRe: Unicode CString and fopen problem Pin
DSPCottage4-May-13 18:38
DSPCottage4-May-13 18:38 
AnswerRe: Unicode CString and fopen problem Pin
Jochen Arndt7-Apr-13 21:00
professionalJochen Arndt7-Apr-13 21:00 
GeneralRe: Unicode CString and fopen problem Pin
DSPCottage4-May-13 18:38
DSPCottage4-May-13 18:38 
Questionquestion about custom symbol in arcmap Pin
ts_chen6-Apr-13 15:40
ts_chen6-Apr-13 15:40 
QuestionIf this fires you have a mixed DEBUG/RETAIL build - now what ? Pin
Vaclav_6-Apr-13 8:34
Vaclav_6-Apr-13 8:34 
AnswerRe: If this fires you have a mixed DEBUG/RETAIL build - now what ? Pin
pasztorpisti6-Apr-13 10:23
pasztorpisti6-Apr-13 10:23 
Questionutf to ascii conversion Pin
khushboo gupta5-Apr-13 23:12
khushboo gupta5-Apr-13 23:12 
Hi,
Can anybody suggest me how can i convert a string from utf8 (like wchar_t toTranscode[] = L"ناعسالاخخ";) format to ascii (like äÇÚÓÇáÇÎÎ)..

I have tried with the following code ..but when i am trying to print char array pToFill it is blank.


C#
#include "stdio.h"
#include <string.h>
#include "stdlib.h"
#define _CRT_SECURE_NO_WARNINGS

int main()
{
    FILE *p = NULL;
    size_t len = 0;
    unsigned int convertedChars = 0;

    int ret;
    
    wchar_t toTranscode[] = L"ناعسالاخخ";
    //wchar_t toTranscode[] = L"hello";
    unsigned int wLent = wcslen((const wchar_t*)toTranscode);
    //------------------------------------------------------
    // a UTF-8 character can have maximum 6 bytes
    //------------------------------------------------------
    int maxCharLen = 6*wLent;
    wchar_t* pWideCharBuf;
    char* pToFill;
    unsigned int i;

    //--------------------------------------------------------------
    // alloc memory for variables.
    //--------------------------------------------------------------
    pWideCharBuf = (wchar_t*)malloc(wLent+1);
    pToFill = (char*)malloc(maxCharLen+1);

    for (i = 0; i < wLent; ++i)
    pWideCharBuf[i] = toTranscode[i];
    pWideCharBuf[wLent] = 0x00;

    memset (pToFill, 0, maxCharLen+1);
  // convert the string

    //ret = wcstombs(pToFill, pWideCharBuf, maxCharLen);

    ret = wcstombs_s(&convertedChars, pToFill, maxCharLen, pWideCharBuf, maxCharLen);
    //ret = wcstombs_s(&convertedChars, pToFill, maxCharLen, pWideCharBuf, _TRUNCATE);
    printf("ret is %d\n", ret);

    printf("the ascii char is  = %s\n", pToFill);
    printf("to test\n");


    p = fopen("hello.txt", "w");
    if (p== NULL) {
       printf("Error in opening a file..");
    }
   len = strlen(pToFill);
   fwrite(pToFill, len, 1, p);
   fclose(p);
   printf("\nWritten Successfuly in the file.\n");

    // pToFill contains the string

    //-------------------------------------------------------
    // clean-up
    //-------------------------------------------------------
    //lete [] pWideCharBuf ;

    // don't forget to
    //delete [] pToFill ;
    return 0;
}



please help
AnswerRe: utf to ascii conversion Pin
Richard MacCutchan6-Apr-13 1:47
mveRichard MacCutchan6-Apr-13 1:47 
GeneralRe: utf to ascii conversion Pin
khushboo gupta6-Apr-13 2:39
khushboo gupta6-Apr-13 2:39 
GeneralRe: utf to ascii conversion Pin
Richard MacCutchan6-Apr-13 3:28
mveRichard MacCutchan6-Apr-13 3:28 
GeneralRe: utf to ascii conversion Pin
khushboo gupta7-Apr-13 18:30
khushboo gupta7-Apr-13 18:30 
GeneralRe: utf to ascii conversion Pin
khushboo gupta9-Apr-13 2:35
khushboo gupta9-Apr-13 2:35 
GeneralRe: utf to ascii conversion Pin
Richard MacCutchan9-Apr-13 5:03
mveRichard MacCutchan9-Apr-13 5:03 
AnswerRe: utf to ascii conversion Pin
MicroVirus6-Apr-13 6:52
MicroVirus6-Apr-13 6:52 
GeneralRe: utf to ascii conversion Pin
khushboo gupta7-Apr-13 18:33
khushboo gupta7-Apr-13 18:33 
QuestionT13 Secure Erase Pin
RomTibi5-Apr-13 11:46
RomTibi5-Apr-13 11:46 
AnswerRe: T13 Secure Erase Pin
dusty_dex5-Apr-13 21:08
dusty_dex5-Apr-13 21:08 
GeneralRe: T13 Secure Erase Pin
RomTibi6-Apr-13 2:18
RomTibi6-Apr-13 2:18 
GeneralRe: T13 Secure Erase Pin
dusty_dex6-Apr-13 7:53
dusty_dex6-Apr-13 7:53 
GeneralRe: T13 Secure Erase Pin
RomTibi6-Apr-13 8:39
RomTibi6-Apr-13 8:39 
AnswerRe: T13 Secure Erase Pin
Randor 6-Apr-13 17:56
professional Randor 6-Apr-13 17:56 
GeneralRe: T13 Secure Erase Pin
RomTibi7-Apr-13 6:34
RomTibi7-Apr-13 6:34 
GeneralRe: T13 Secure Erase Pin
Joe Marley9-Apr-13 11:32
Joe Marley9-Apr-13 11:32 
QuestionScreen Lock for MFC App Pin
Donguy19765-Apr-13 11:31
Donguy19765-Apr-13 11:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.