[C++(.NET)] StringCoords function (Sdk)

[C++(.NET)] StringCoords function // Sdk

1  |  

strike rapier

Dec 16, 2002, 8:10pm
Hello All,
Im currently experiencing a small problem with a function I have created
to basicly do the same as the VB StringCoords(x as long, y as long, z as
long, yaw as long) function. However whenever I try it the entire thing goes
up in flames, if any of you could assist with this rather puzzling problem.

Ive included the function in a txt file so it retains its tab alignment to
make it easier for people to read :)

The error comes up as critical error, cannot write to memory, and crashes
the program into debug mode.

It also highlights this in output.c if its any help.

#ifdef _UNICODE
if (_putwc_lk(ch, f) == WEOF)
#else /* _UNICODE */
if (_putc_lk(ch, f) == EOF)
#endif /* _UNICODE */
*pnumwritten = -1;

Any help apreciated :)

- Mark
*goes to work out why the IDE says I cant write to program database*


Dec 16, 2002, 9:10pm

I don't see the attachment

[View Quote]

strike rapier

Dec 16, 2002, 9:47pm
Good Point.. damned OE

[View Quote]
begin 666 cpp_stringcoords.txt
M=F]I9"!3=')I;F=#;V]R9',H;&]N9R!8+"!L;VYG(%DL(&QO;F< at 6BP at ;&]N
M9R!905<I#0I[#0H)+RI$96-L86ER(&)U9F9E<B!V87)I86)L97, at 87, at 8VAA
M<B!P;VEN=&5R<RHO#0H)8VAA< at DJ8G5F9F5R"0D]("(B.PT*"6-H87()*GAB
M=69F97()/2 B(CL-" at EC:&%R"2IY8G5F9F5R"3T at (B([#0H)8VAA< at DJ>F)U
M9F9E< at D]("(B.PT*"6-H87()*GEA=V)U9F9E< at D]("(B.PT*"61O=6)L90ED
M>&)U9F9E< at D](# [#0H)9&]U8FQE"61Y8G5F9F5R"3T at ,#L-" at ED;W5B;&4)
M9'IB=69F97()/2 P.PT*"61O=6)L90ED>6%W8G5F9F5R"3T at ,#L-" at T*"2\J
M1&EV:61E(&)Y(#$P,# at =&\ at 9V5T('1H92!A8W1U86P at 8V]O<F1I;F%T97, at
M97AC97!T(&9O<B!905< at =VAE;B!D:79I9&4 at 8GD at ,3 J+PT*"61X8G5F9F5R
M"3T)6" O(#$P,# [#0H)9'EB=69F97()/0E9("\ at ,3 P,#L-" at ED>F)U9F9E
M< at D]"5H at +R Q,# P.PT*"61Y87=B=69F97()/0E8("\ at ,3 [#0H-" at DO*E at at
M0V]O<F1I;F%T92 H16%S=" M/B!797-T*2HO#0H):68 at *&1X8G5F9F5R(#P at
M,"E[#0H)"7-P<FEN=&8H>&)U9F9E<BPB)60 at 92(L9'AB=69F97(I.PT*"7T-
M" at EE;'-E>PT*"0ES<')I;G1F*'AB=69F97(L(B5D('<B+&1X8G5F9F5R*3L-
M" at E]#0H-" at DO*ED at 0V]O<F1I;F%T92 H3F5G871I=F4 at +3X at 4&]S:71I=F4I
M*B\-" at ES<')I;G1F*'EB=69F97(L(B5D(&$B+&1Y8G5F9F5R*3L-" at T*"2\J
M6B!#;V]R9&EN871E("A3;W5T:" M/B!.;W)T:"DJ+PT*"6EF("AD>F)U9F9E
M<B \(# I>PT*"0ES<')I;G1F*'IB=69F97(L(B5D(',B+&1Z8G5F9F5R*3L-
M" at E]#0H)96QS97L-" at D)<W!R:6YT9BAZ8G5F9F5R+"(E9"!N(BQD>F)U9F9E
M<BD[#0H)?0T*#0H)+RI#;VUP:6QE(&EN=&\ at <VEN9VQE(&)U9F9E<BHO#0H)
M>F)U9F9E<BQY87=B=69F97(I.PT*"7-3=')I;F=#;V]R9', at /2!B=69F97([
M#0I]#0H-"G-3=')I;F=#;V]R9', at :7, at 9&5C;&%I<F5D(&%S(&=L;V)A;"!C


Dec 16, 2002, 10:15pm
That was too easy :)

Your buffers are all only 1 byte large (the '\0' that
terminates the "" string)

With sprintf you copy several characters into this location
that can hold only 0 characters (!)

Fix :

make larger buffers from the buffer variables or allocate them large enough.

#define LARGE_ENOUGH 30

so it's either

static char buffer[LARGE_ENOUGH];


char *buffer=NULL;

if (! buffer)
buffer = malloc (LARGE_ENOUGH);

Oh, and yaw is never filled

What about this version :

void StringCoords(long X, long Y, long Z, long YAW)
char buffer[LARGE_ENOUGH];

/*Divide by 1000 to get the actual coordinates except for YAW when divide by 10*/
dxbuffer = X / 1000;
dybuffer = Y / 1000;
dzbuffer = Z / 1000;
dyawbuffer = X / 10;

sprintf (buffer, "%d%c %d%c %da %d"
, abs(dxbuffer), dxbuffer<0 ? 'e' : 'w'
, abs(dzbuffer), dzbuffer<0 ? 's' : 'n'
, dybuffer, dyawbuffer);

if (sStringCoords)
free (sStringCoords);

sStringCoords = strdup (buffer);

with sStringCoords global declared like this :
char* sStringCoords = NULL;

[View Quote]


Dec 16, 2002, 10:27pm
oops, I didn't see - you use double precision variables for your dxbuffer and so. If you want decimal places, you have to use %lf instead of %d

strike rapier

Dec 16, 2002, 10:29pm
Many Thanks Annanas :D Im going to check though it and just convert :D
thanks again
[View Quote]

strike rapier

Dec 17, 2002, 5:30pm
Many Thanks Annanas :D Im going to check though it and just convert :D
thanks again
[View Quote]


Dec 22, 2002, 7:25pm
You've got your N/S and W/E reversed.


[View Quote]


Dec 22, 2002, 8:29pm
well, quick typed into the newsreader without having
tested first *g

Thanks :)

[View Quote]


Dec 23, 2002, 12:31am
Figured that was the case... easy to do that. :) You're welcome.


[View Quote]

1  | is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn