#include <stdio.h> //for printf
//------------------------------------------
// STRUCTS: Better storage than ziplock
//------------------------------------------
/*
This is the definition of our LOCATION struct. LOCATION is the
name we gave it, and the variables inside the braces are refered to
as object members. x and y are members of LOCATION. Since we
have defined LOCATION as a struct containing 2 integers, we can
now use LOCATION as a data type just like we can use any other
data type such as char, int, float, etc. Theres no particular need for
our name to be in all CAPS, but it can sometimes make it easier to
notice and identify user defined data types (and #defines) when
they are all CAPS. Its an organisational preference.
*/
struct LOCATION
{
int x;
int y;
};
//------------------------------------------
// MAIN
//------------------------------------------
int main(void)
{
/*
Here we are going to declare two variables of type LOCATION. Once
will be called Me, and a second will be called You. So far we see nothing
out of the ordinary. They are declared just like any other variable.
*/
LOCATION Me;
LOCATION You;
/*
Now it gets interesting. Since normal variables only hold a single value,
its okay to say that MyInt = 10; Here, we cannot say Me = 10, since Me
is of type LOCATION, and LOCATION holds two values, x and y. This
is where the ??? operator comes into play. We can now assign the values
of both the x and y variables contained in Me to whatever we want.
*/
Me.x = 10;
Me.y = 50;
//Now we do exactly the same thing for 'You', but with different values.
You.x = 41;
You.y = 3;
//Now we display the values contained in Me, and You.
printf("I am at %i X, and %i Y!\n", Me.x, Me.y);
printf("You are at %i X, and %i Y!\n", You.x, You.y);
return 0;
}