Skip to content

Instantly share code, notes, and snippets.

@kawa-
Last active October 11, 2015 19:18
Show Gist options
  • Save kawa-/3907170 to your computer and use it in GitHub Desktop.
Save kawa-/3907170 to your computer and use it in GitHub Desktop.
Object Oriented C lang
# just wrote them.
# ふと思いついたので書いてみた。これでOOPなCじゃんっていう。継承とか出来ないけど。
#include <stdio.h>
struct person {
double height;
double weight;
int age;
char* name;
char* description;
};
void person_print_infomation(struct person someone)
{
printf("-----\nHeight: %.1f\nWeight: %.1f\nAge: %d\nName: %s\nDesc: %s\n-----\n", someone.height, someone.weight, someone.age, someone.name, someone.description);
}
void person_print_bmi(struct person someone)
{
printf("BMI of %s is %.1f.\n",someone.name, someone.weight * someone.weight / someone.height);
}
int main (int argc, const char * argv[]) {
struct person ichiro = {
180.3,
71,
38,
"Ichiro",
"MLB Player"
};
person_print_infomation(ichiro);
person_print_bmi(ichiro);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment