Page 1 of 1

Basics on Creating a Struct

PostPosted: Fri Jan 11, 2013 5:10 am
by Hblade
First, what is a struct? A struct is a "structured record" that aggregates a fixed set of labelled objects, possibly of different types, into a single object. (http://en.wikipedia.org/wiki/Struct_%28 ... anguage%29)

Let's begin with actually making a struct.
Code: Select all
struct PlayerInfo {
    int age;
    char *name;
};


The ; is important after the }. Now we have created a struct. What you can do NOW is create a second struct and give it the properties of our first struct like so:
Code: Select all
struct Player1 PlayerInfo;
struct Player2 PlayerInfo;


Now what you can do from there is define seperate information, like this:
Code: Select all
Player1.name="Bob";
Player1.age=22;
Player2.name="Dave";
Player2.age=25;



See how this works? Hope it helps :)!