This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Interesting char *


Interesting char *

Postby brendan » Jan 24, 2003 @ 2:36am

I've recently been having issues with chars...
I have the following struct

struct player_attribs {
char *name;
};

there is other stuff in it as well, anyhow....
I then:

player_attribs player[20];

do I still have to

player[5].name = new char[10] = "1234567890";

or not?

it "seems" I can just:

player[5].name = "fred";

your comments?
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby MirekCz » Jan 24, 2003 @ 3:45am

you still have to do it.
Possibly your code is going very bad somewhere and the char *name structure is pointing to a part of memory you're using (ee... one of the player_attribs struct, maybe?:-)
So each time you save something there you're wildly writing all over this structure... or maybe somewhere else.. god knows... just don't do it;-)
you have to either have something like

char name[256];
char *namepointer;
namepointer=name;

or like you said, use new/malloc/whatever


btw think about it a little.. you create a pointer without giving size and your poor PPC should know how large your array is? :-)
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Interesting char *

Postby Dan East » Jan 24, 2003 @ 5:52am

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Interesting char *

Postby andys » Jan 24, 2003 @ 12:20pm

andys
pm Member
 
Posts: 230
Joined: Jan 19, 2002 @ 6:19pm
Location: London


Postby brendan » Jan 24, 2003 @ 2:19pm

hmmm, yes Dan, you could be right... I didn't test the new char[5] = "12345"; idea etc....

I was having issues when pre defining them to a size...

i.e the command

player[5].name = "12345"; failed, because cant assign char[5] to *char[5] which now makes perfect sence.... lol

but the code was "working" by just leaving it as char *name

then just saying

player[5].name = "fred";

but I think I'll just "fix it" to the prefered method... and yes the null (\0) is a valid point....

it could be the the point was just renamed to the "name"?
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Sm!rk » Jan 25, 2003 @ 1:59am

User avatar
Sm!rk
pm Member
 
Posts: 172
Joined: Dec 16, 2002 @ 4:40pm


Postby gamefreaks » Jan 25, 2003 @ 12:42pm

What if everything is an illusion and nothing exists? In that case, I definitely overpaid for my carpet. -Woody Allen
User avatar
gamefreaks
pm Insider
 
Posts: 466
Joined: Oct 20, 2001 @ 8:52pm
Location: Leicester, England


Postby Hosed » Jan 25, 2003 @ 2:50pm

L. L. Goodwin<BR>Purveyor of Code<BR><A href="http://www.planettribes.com/hosed/">Hosed's House of Code</A>
User avatar
Hosed
pm Member
 
Posts: 249
Joined: Jan 3, 2002 @ 2:51am
Location: Montana, USA


Postby Orpe » Jan 25, 2003 @ 5:25pm

User avatar
Orpe
pm Member
 
Posts: 78
Joined: Sep 16, 2001 @ 6:51pm
Location: Stockholm, Sweden


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum