Created
December 12, 2012 02:52
-
-
Save josefsalyer/4264448 to your computer and use it in GitHub Desktop.
struct your stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.c | |
// StructuredObjects | |
// | |
// Created by john salyer on 12/4/12. | |
// Copyright (c) 2012 Josef Salyer. All rights reserved. | |
// | |
#include <stdio.h> | |
//#include <stdbool.h> //this is what you use if you are just using C, but we're not | |
#include <objc/objc.h> //required for boolean (true/false) type | |
// define our structure | |
typedef struct OVEN | |
{ | |
BOOL isOn; //a boolean is really an integer, shhhh don't tell anyone | |
float temperature; | |
int timer; | |
} OVEN; | |
typedef struct PIZZABOX | |
{ | |
float howMuchPizzaIsLeft; //1.00 after eating it's .25 | |
BOOL isHot; // true or false, 1 or 0, YES or NO | |
BOOL isScrumptious; | |
float deliveryTime; | |
} PIZZABOX; | |
int main(int argc, const char * argv[]) | |
{ | |
// create an 'instance' of our pizza box | |
PIZZABOX myPizzaBox = | |
{ | |
.howMuchPizzaIsLeft = .25, | |
.isHot = YES, | |
.isScrumptious = YES, | |
.deliveryTime = 30.5 | |
}; | |
printf("howMuchPizzaIsLeft: %f, isHot: %d, isScrumptious: %d, deliveryTime: %f", myPizzaBox.howMuchPizzaIsLeft, myPizzaBox.isHot, myPizzaBox.isScrumptious, myPizzaBox.deliveryTime); | |
// %f = float | |
// %d = digit | |
// %s = string (table this) | |
// create an 'instance' of our oven | |
OVEN myOven = | |
{ | |
.isOn = YES, | |
.temperature = 325.6, | |
.timer = 90 | |
}; | |
//print the status of our oven | |
printf("isOn: %s, temperature: %f, timer: %d \n", | |
(myOven.isOn) ? "YES" : "NO", //OMG!!! TERNARY OPERATOR! | |
myOven.temperature, | |
myOven.timer); | |
//turn the oven off | |
myOven.isOn = NO; | |
//print the status of our oven showing it's off | |
printf("isOn: %s, temperature: %f, timer: %d \n", | |
(myOven.isOn) ? "YES" : "NO", | |
myOven.temperature, | |
myOven.timer); | |
/* | |
Now all that printing seems a little annoying | |
*/ | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment