hoangdangninh
4/13/2017 - 5:55 AM

object-oriented in c

object-oriented in c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Book {
  int  pages;
  char author[50];
  void (*info)(struct Book);
} Book;

void info(Book b) {
  printf("this is the information of the book\n");
  printf("pages: %d\n", b.pages);
  printf("author: %s\n", b.author);
}

int main() {

  Book b;
  b.pages = 28;
  strcpy(b.author, "hoang");
  b.info = &info;
  b.info(b);

  return 0;
}