Created
October 25, 2014 11:01
-
-
Save ixn/0a410e8b564359d10219 to your computer and use it in GitHub Desktop.
Simple object oriented in C (http://deeprhezy.tumblr.com)
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
#include "object.h" | |
int | |
main(int argc, char* argv[]) | |
{ | |
/* Deklarasi obj sebagai object */ | |
object* obj; | |
/* Melakukan pengalokasian memory pada obj */ | |
obj = object_new(); | |
/* Deklarasi variable object 1 & object 2 */ | |
char object1[1024]; | |
char object2[1024]; | |
printf("Masukkan nilai object 1 = "); | |
scanf("%s",object1); | |
// Mengisi nilai object 1 pada char array, scanf tidak bisa mengisi langsung ke pointer. | |
// jad digunakan char array untuk mengisi nilai object 1 dari scanf | |
printf("Masukkan nilai object 2 = "); | |
scanf("%s",object2); | |
// Mengisi nilai object 2 pada char array, scanf tidak bisa mengisi langsung ke pointer. | |
// jadi digunakan char array untuk mengisi nilai object 2 dari scanf | |
// Mengisikan obj->object1 yang berasal dari nilai object1 | |
obj->object1=object1; | |
// Mengisikan obj->object2 yang berasal dari nilai object2 | |
obj->object2=object2; | |
//Memanggil fungsi display untuk melakukan printf | |
object_display(obj); | |
//Memanggil fungsi penghapusan memory yang digunakan oleh obj | |
object_free(obj); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment