Results 1 to 7 of 7

Thread: ASCII->UNICODE

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    166

    ASCII->UNICODE

    Hello,
    I friend of mine has a homework, but can't do it at all. So I decided to post it here. So, he must do a C program that converts ASCII to UNICODE files incl. Bulgarian language. I googled for it, but can't find anything. Actually I don't want the full code, but I need only some piece of code that do the converting.

    Best regards!
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  2. #2
    Junior Member
    Join Date
    Mar 2007
    Posts
    7
    Unicode is an abstract mapping of integers to symbols. It is not a character encoding. You need a character encoding.

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    Here is what I found:

    * Convert ASCII to Unicode since all data is saved as Unicode.
    275 */
    276 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
    277 {
    278 INT len;
    279 WCHAR *to;
    280
    281 TRACE("<%s>\n", frstr);
    282 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
    283 to = Alloc(len * sizeof(WCHAR));
    284 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
    285 *tostr = to;
    286 }
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  4. #4
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    Hi again,
    I did the program, but now I have another problem. It outputs me only the first 5 chars of the sentence and didn't output the Cyrillic. Here is the code if somebody can help:

    #include <stdio.h>
    #include <string.h>
    #include <wchar.h>
    #include "convert.h"

    bool AsciiToUnicode(const char * szAscii, wchar_t * szUnicode)


    {
    int len, i;
    if((szUnicode == NULL) || (szAscii == NULL))
    return false;
    len = strlen(szAscii);

    for(i=0;i<len+1;i++)
    *szUnicode++ = static_cast<wchar_t>(*szAscii++);
    return true;
    }

    int main()
    {
    FILE *f;
    char s[1000];
    wchar_t rch;
    f=fopen("C:\\a.txt","r");
    if (!f)
    return 1;
    while (fgets(s,1000,f)!=NULL)
    {
    if(AsciiToUnicode(s, &rch))
    printf("Not testing:%ls\n", &rch);
    else printf("Testing:%s\n", s);
    }
    fclose(f);
    return 0;
    }

    ... and here is Convert.h:

    #ifndef CHARSET_CONVERSION
    #define CHARSET_CONVERSION
    #include <stddef.h>
    bool AsciiToUnicode(const char * szAscii, wchar_t * szUnicode);
    bool UnicodeToAscii(const wchar_t * szUnicode, char * szAscii);
    #endif

    Best regards!
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  5. #5
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    I change the function AsciiToUnicode to:

    wchar_t* ASCIIToUnicode(const char *ascii )
    {
    //first it would be best to discover where the '\0' is located
    int i, length;
    length = strlen(ascii);
    for(i=0;i<length;++i)
    {
    if(ascii[i]=='\0')
    break;
    }
    ++i;
    //now we can make the actual Unicode array
    char *unicode = (char*)calloc(i,sizeof(wchar_t));
    // if(unicode==NULL)
    // return 1;
    for(int j=0;j<i;++j)
    {
    unicode[j*2]=ascii[j];
    unicode[j*2+1]='\0';
    }
    return (wchar_t*)unicode;
    }

    Now it prints out all, but the Cyrillic shows with hieroglyphs
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  6. #6
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    Can anybody help? It is urgent ,,,
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

  7. #7
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    Please, the admin can delete this thread ...
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

Similar Threads

  1. Fun with ASCII folders
    By el-half in forum The Security Tutorials Forum
    Replies: 10
    Last Post: January 16th, 2004, 05:06 PM
  2. ASCII & Unicode
    By Propaganda in forum AntiOnline's General Chit Chat
    Replies: 1
    Last Post: August 6th, 2003, 02:32 AM
  3. ATI Card Pushes Limits of ASCII Gaming
    By cwk9 in forum Tech Humor
    Replies: 0
    Last Post: February 28th, 2003, 11:38 PM
  4. hex 2 ascii viewer
    By lench in forum AntiOnline's General Chit Chat
    Replies: 1
    Last Post: December 5th, 2002, 02:49 PM
  5. Network Vulnerabilities and Countermeasures
    By Joey_Batch_File in forum The Security Tutorials Forum
    Replies: 10
    Last Post: September 20th, 2002, 09:03 PM

Posting Permissions

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