UnicodeQuery

R

rajesh.ba

Hi ,

I am trying some sample programs with unicode strings.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <windows.h>



int _tmain(int argc, _TCHAR* argv[])
{
double* my_len;
wchar_t* my_string = (wchar_t *) malloc(sizeof(wchar_t) *100);
wchar_t* my_string2 = (wchar_t *) malloc(sizeof(wchar_t) *100);

double* my_len1 = (double*)my_string2;

swprintf(my_string,100,L"ABCDEFGH");
my_len = (double*)(my_string);

*(my_len1) = *my_len;

wprintf(L"my string2 is %s\n",my_string2);

wprintf(L"my string is %s\n",my_string);

}

This program gives an output

my string2 is
ABCD??????????????????????????????????????????????????????????????
????????????????????????????????????
my string is ABCDEFGH


How can i make my_string2 to print "ABCDEFGH"?


Regards
Rajesh
 
C

CBFalconer

I am trying some sample programs with unicode strings.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])

So far you have used the non-existant (in standard C) headers
stdafx.h and windows.h, the reserved for the implementation
identifiers _tmain and _TCHAR. This newsgroup deals with the
standard C language, as defined by the various ISO standards, only.

Either confine yourself to standard C, or go to a newsgroup that
deals with your peculiar system.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
A

Andrew Poelstra

Hi ,

I am trying some sample programs with unicode strings.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <windows.h>



int _tmain(int argc, _TCHAR* argv[])
{
double* my_len;
wchar_t* my_string = (wchar_t *) malloc(sizeof(wchar_t) *100);
wchar_t* my_string2 = (wchar_t *) malloc(sizeof(wchar_t) *100);

double* my_len1 = (double*)my_string2;

swprintf(my_string,100,L"ABCDEFGH");
my_len = (double*)(my_string);

*(my_len1) = *my_len;

wprintf(L"my string2 is %s\n",my_string2);

wprintf(L"my string is %s\n",my_string);

}

This program gives an output

my string2 is
ABCD??????????????????????????????????????????????????????????????
????????????????????????????????????
my string is ABCDEFGH


How can i make my_string2 to print "ABCDEFGH"?


Regards
Rajesh

I don't recognize 'windows.h' and 'wchar.h'. And you haven't shown
what's in "stdafx.h".

Perhaps you should post this in comp.windows.programmer or some such group.
 
V

void * clvrmnky()

Andrew said:
Hi ,

I am trying some sample programs with unicode strings.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
double* my_len;
wchar_t* my_string = (wchar_t *) malloc(sizeof(wchar_t) *100);
wchar_t* my_string2 = (wchar_t *) malloc(sizeof(wchar_t) *100);

double* my_len1 = (double*)my_string2;

swprintf(my_string,100,L"ABCDEFGH");
my_len = (double*)(my_string);

*(my_len1) = *my_len;

wprintf(L"my string2 is %s\n",my_string2);

wprintf(L"my string is %s\n",my_string);

}

This program gives an output

my string2 is
ABCD??????????????????????????????????????????????????????????????
????????????????????????????????????
my string is ABCDEFGH

How can i make my_string2 to print "ABCDEFGH"?

I don't recognize 'windows.h' and 'wchar.h'. And you haven't shown
what's in "stdafx.h".
Well, wchar.h is standard as of Amendment 1 to ANSI X3.159-1989. This,
of course, does not address the problem that my_string2 is pointing at
garbage. I admit that I have no clear idea why someone would write code
like this.
 
R

Roberto Waltman

code deleted, a few interesting statements left:
double* my_len;
wchar_t* my_string = (wchar_t *) malloc(sizeof(wchar_t) *100);
wchar_t* my_string2 = (wchar_t *) malloc(sizeof(wchar_t) *100);
double* my_len1 = (double*)my_string2;
swprintf(my_string,100,L"ABCDEFGH");
my_len = (double*)(my_string);
*(my_len1) = *my_len;
wprintf(L"my string2 is %s\n",my_string2);
wprintf(L"my string is %s\n",my_string);
my string2 is
ABCD??????????????????????????????????????????????????????????????
????????????????????????????????????
my string is ABCDEFGH
How can i make my_string2 to print "ABCDEFGH"?

You initialize my_string, then copy sizeof(double)/sizeof(wchar_t)
chars from my_atring into my_string2 without properly terminating it
and leaving the rest uninitialized.

What are you trying to accomplish? If you want to copy strings, look
for a library function that does just that.
 
R

Richard Bos

int _tmain(int argc, _TCHAR* argv[])
{
double* my_len;
wchar_t* my_string = (wchar_t *) malloc(sizeof(wchar_t) *100);
wchar_t* my_string2 = (wchar_t *) malloc(sizeof(wchar_t) *100);

double* my_len1 = (double*)my_string2;

swprintf(my_string,100,L"ABCDEFGH");
my_len = (double*)(my_string);

*(my_len1) = *my_len;

Apart from all other problems, what makes you think using pointers to
double for copying wide character strings is a reasonable thing to do?

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top