3 Replies - 256 Views - Last Post: 12 October 2012 - 05:50 PM Rate Topic: -----

#1 xriBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Structures to Functions in C

Posted 12 October 2012 - 04:01 PM

I'm having trouble in passing my structures to simple void functions. I get stucked here for half an hour and couldn't find a solution in the web and in my past programs.

Here's what I attempted. (Some functions are not defined yet, until I got the above error lines correct.)

/* RPG
*  @authors: Me, Myself, and I!
*  @date:
*/

#include<stdio.h>

// Weapon structure consists of name and damage points
typedef struct{
  char name[30];
  int damagePoints;
} Weapon;

// Armor structure consists of name and defense points
typedef struct{
  char name[30];
  int defensePoints;
} Armor;

// Basic structure of a player. For now, player could only hold one armor and one weapon.
typedef struct{
  char name[30];
  int healthPoints;
  Weapon weapon;
  Armor armor;
} Player;


// Sentinels
Player *PlayerPointer; // alias used for referencing players
Weapon *WeaponPointer; // alias used for referencing weapons
Armor  *ArmorPointer;  // alias used for referencing armors

// Functions
Player displayStatOfPlayer(PlayerPointer aPlayer);
void createPlayer(PlayerPointer *playerRef, char name);
void createWeapon(WeaponPointer *weaponRef, char name);
void createArmor (ArmorPointer *armorRef, char name);

int main () {




  return 0;
}


void createPlayer(PlayerPointer *playerRef, char name) {

}

void createWeapon(WeaponPointer *weaponRef, char name) {

}

void createArmor (ArmorPointer *armorRef, char name) {

}






Any help would be appreciated. Thank you.

This post has been edited by GunnerInc: 12 October 2012 - 04:25 PM
Reason for edit:: Modified authors


Is This A Good Question/Topic? 0
  • +

Replies To: Structures to Functions in C

#2 Ytry  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 120
  • Joined: 25-July 12

Re: Structures to Functions in C

Posted 12 October 2012 - 04:14 PM

So, what exactly do you need help with?

This post has been edited by Ytry: 12 October 2012 - 04:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 xriBit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Re: Structures to Functions in C

Posted 12 October 2012 - 04:31 PM

The compiler says that there are errors.

error: variable or field 'displayStatOfPlayer' declared void

View PostxriBit, on 12 October 2012 - 04:26 PM, said:

The compiler says that there are errors.

error: variable or field 'displayStatOfPlayer' declared void


and many other related errors...

Oh! I already figured it out.

I missed on putting typedef to my Structure pointers.

Geez, I answered my own question.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10488
  • View blog
  • Posts: 38,865
  • Joined: 27-December 08

Re: Structures to Functions in C

Posted 12 October 2012 - 05:50 PM

Moved to C/C++.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1