Structs and pointers

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Structs and pointers

Post by PrOfUnD Darkness »

I have a pointer to a struct like this:

struct list_type *vmuq;

I can manipulate this struct without any problem, but when I pass it to a function like this:

salva_questoes_vmu(vmuq);

looks like it don't pass anything at all, I can't access any value of it from inside the function:

void salva_questoes_vmu(struct list_type *tmpvmuq) {
...
bla bla bla
...

printf("%s\n", tmpvmuq->right);

the printf above just prints nothing...


Any idea?
q_006
Mental DCEmu
Mental DCEmu
Posts: 415
Joined: Thu Oct 10, 2002 7:18 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by q_006 »

coluld you show the code for that function?

it'll better help others (such as myself) who would like to help you.
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Post by PrOfUnD Darkness »

There's nothing special on it. It just use the KOS vmu functions to create a package. Even if the first line of the function is the printf shown above, it doesn't print anything.



PD
Vorrtexx
Insane DCEmu
Insane DCEmu
Posts: 138
Joined: Sun Apr 06, 2003 5:29 am
Has thanked: 0
Been thanked: 0
Contact:

Post by Vorrtexx »

are you allocating memory for the structure pointer?

Code: Select all

	list_type *vmuq = (list_type *)malloc(sizeof(list_type));

	strcpy(vmuq->right,"blah blah");
	salva_questoes_vmu(vmuq);



	void salva_questoes_vmu(list_type *tmpvmuq) { 
		printf("%s\n", tmpvmuq->right);
	}

PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Post by PrOfUnD Darkness »

Yes, I'm.

Code: Select all

strcpy(vmuq.right,"blah blah");
printf("%s\n", vmuq.right);
salva_questoes_vmu(vmuq);

void salva_questoes_vmu(list_type *tmpvmuq) {
printf("%s\n", tmpvmuq->right);
}
On the code above, the first printf works, the second one don't :(
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Has thanked: 0
Been thanked: 0
Contact:

Post by GPF »

somehow you have to pass the address of where the struct begins.

Code: Select all

struct list_type *vmuq, z;

z=&vmuq;

salva_questoes_vmu(z);
or just

Code: Select all

salva_questoes_vmu(&vmuq);
It been awhile so I could be wrong on the syntax.

Troy
Vorrtexx
Insane DCEmu
Insane DCEmu
Posts: 138
Joined: Sun Apr 06, 2003 5:29 am
Has thanked: 0
Been thanked: 0
Contact:

Post by Vorrtexx »

PrOfUnD Darkness wrote:Yes, I'm.

Code: Select all

strcpy(vmuq.right,"blah blah");
printf("%s\n", vmuq.right);
salva_questoes_vmu(vmuq);

void salva_questoes_vmu(list_type *tmpvmuq) {
printf("%s\n", tmpvmuq->right);
}
On the code above, the first printf works, the second one don't :(
Well from the code you presented, it doesn't look like you declared vmuq as a pointer, because you are accessing vmuq wit the "." in the first and 2nd lines rather than "->"

Then you're passing the variable to a function that required the address of the variable. So you might want to replace your third line with salva_questoes_vmu(&vmuq).

if vmuq has been declared as a pointer, then you can call it like so:
salva_questoes_vmu(vmuq)
Post Reply