Skip to content

Instantly share code, notes, and snippets.

@TheCodeEngine
Created April 24, 2013 13:03
Show Gist options
  • Save TheCodeEngine/5451964 to your computer and use it in GitHub Desktop.
Save TheCodeEngine/5451964 to your computer and use it in GitHub Desktop.
A Stuct in a function example
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
const char *name;
const char *species;
int age;
} turtle;
void printTurtle(turtle *t)
{
/*
Importent is that *t.name nicht das gleiche ist wie (*t).name
- (*t).age or t->age = I am the age of the turtle pointed to by t
- *t.age = I am the contents of the memory location given by t.age
*/
fprintf(stdout, "Name: %s\n", (*t).name);
fprintf(stdout, "Species: %s\n", t->species);
fprintf(stdout, "Age: %d\n", (*t).age);
}
int main(int argc, char const *argv[])
{
turtle myturtle = { "Mytutrtle", "Leatherback sea turtle", 99 };
printTurtle(&myturtle);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment