Basics on Creating a Struct

Learn how to make certain types of games and use gameEditor.

Basics on Creating a Struct

Postby Hblade » Fri Jan 11, 2013 5:10 am

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 :)!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest