Struct Introduction Tutorial (revision 120925-r01KI)

Return to Lab 02

  • Create cobastruct.c file and fill it with the below content. Replace [nama_anda] with your name (example: Ramot Stephanus) and [NPM_anda] with your student ID (example: 1202000818) without the square brackets. Replace TOKEN with your token.
    $ vi cobastruct.c
    i

    // Saya, [nama_anda] dengan NPM [NPM_anda], 
    // mengetik sendiri program ini.
    // ZCZC TOKEN
    
    #include<stdio.h>
    
    typedef struct person
    {
       char *name;
       int age;
    } PERSON;
    
    int main()
    {
       PERSON pp;
       pp.name = "John Smith";
       pp.age = 25;
       printf("%s\n",pp.name);
       printf("%d\n",pp.age);
       return 0;
    }
  • Compile the program to be executable cobastruct.
  • Run cobastruct and record the output to cobastruct.txt, the result must be exactly the same with below:
    $ cat cobastruct.txt

    John Smith
    25
  • From this tutorial, you are expected to understand that struct functions just like Object in Java programming language.
  • This is the end of struct tutorial.

Return to Lab 02
Kembali ke Wiki