www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/12/09:07:06

Message-ID: <35A74233.63E33C70@uol.com.br>
Date: Sat, 11 Jul 1998 07:45:07 -0300
From: "Juciê Dias Andrade" <jucie AT uol DOT com DOT br>
MIME-Version: 1.0
To: Jason Nehf <zolaar AT earthlink DOT net>
CC: djgpp AT delorie DOT com
Subject: Re: question on structures
References: <6o63dl$ojc$1 AT ash DOT prod DOT itd DOT earthlink DOT net>

What is the problem with '&', Jason ?
You can use '&' with structs too.

	#include <stdio.h>

	struct Test
	{
		char *one, *two, *three;
	};

	void fun(Test &x)
	{
		puts(x.one);
		puts(x.two);
		x.three = "me";
	}

	int main()
	{
		Test s;
		s.one = "This works";
		s.two = "for";
		fun(s);
		puts(s.three);
		return 0;
	}

[]s

Jason Nehf escreveu:
> 
> How would I pass a structure in a function, then have the function change
> the values in the structure?  I know with regular variables, you just pass
> them by putting a '&' in front of the variable, but is there an equivilant
> with structures?  Specifically, I'm trying to pass a structure with all of a
> RPG character's attributes (hitpoints, strength, dexterity, etc), and have
> it accelerate the character to a specific level.  I know i could, instead of
> passing a structure, pass each variable individually, but that is a LOT of
> work that could be saved by passing a structure.  Any help would be greatly
> appreciated!
> 
> regards,
> 
> Jason Nehf

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019