Skip to content

Instantly share code, notes, and snippets.

@TheCodeEngine
Created April 24, 2013 13:02
Show Gist options
  • Save TheCodeEngine/5451961 to your computer and use it in GitHub Desktop.
Save TheCodeEngine/5451961 to your computer and use it in GitHub Desktop.
A struct example
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
struct fish
{
const char *name;
const char *species;
int teeth;
int age;
};
struct fish snappy = {"Snappy", "Piranha", 69, 4};
struct fish gnasher = snappy;
fprintf(stdout, "Fish Name: %s\n", snappy.name);
fprintf(stdout, "Fish Species: %s\n", snappy.species);
fprintf(stderr, "Fish Age: %d\n", snappy.age);
/* The same with typedef */
typedef struct cell_phone
{
int number;
} phone;
phone p = { 0151 };
fprintf(stdout, "Phone Number: %d\n", p.number);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment