-
April 18th, 2007, 08:13 AM
#1
Senior Member
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!
-
April 18th, 2007, 08:41 AM
#2
Junior Member
Unicode is an abstract mapping of integers to symbols. It is not a character encoding. You need a character encoding.
-
April 18th, 2007, 09:25 AM
#3
Senior Member
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 }
-
April 19th, 2007, 08:53 PM
#4
Senior Member
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!
-
April 19th, 2007, 10:15 PM
#5
Senior Member
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
-
April 21st, 2007, 09:13 AM
#6
Senior Member
Can anybody help? It is urgent ,,,
-
April 21st, 2007, 03:06 PM
#7
Senior Member
Please, the admin can delete this thread ...
Similar Threads
-
By el-half in forum The Security Tutorials Forum
Replies: 10
Last Post: January 16th, 2004, 05:06 PM
-
By Propaganda in forum AntiOnline's General Chit Chat
Replies: 1
Last Post: August 6th, 2003, 02:32 AM
-
By cwk9 in forum Tech Humor
Replies: 0
Last Post: February 28th, 2003, 11:38 PM
-
By lench in forum AntiOnline's General Chit Chat
Replies: 1
Last Post: December 5th, 2002, 02:49 PM
-
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
-
Forum Rules
|
|