SAM Example 0

From SoOS

Jump to: navigation, search

Contents

[edit] Description

This example shows how to initialize and destroy a SAM context.

[edit] Code

  1. #include <stdio.h>
  2. #include <sam.h>
  3.  
  4. int main(void)
  5. {
  6.   /* Declare a SAM context variable */
  7.   SAM_t sam_context;
  8.  
  9.  
  10.   /* Initialize the SAM context */
  11.   SAM_Init(&sam_context);
  12.  
  13.   /* Destroy the SAM context */
  14.   SAM_Destroy(&sam_context);
  15.  
  16.  
  17.   /* Print the version of the used SAM library */
  18.   /* No context is needed for this operations */
  19.   printf("%s\n", SAM_Version_string());
  20.   printf("%s\n", SAM_Date_string());
  21.  
  22.   return 0;
  23. }

[edit] Explanation

In line 7 the context variable is declared, that has to be passed by reference to the commands in line 11 and 14, that initialize and destroy the context.

How to obtain the version and date of the library is shown with the commands in lines 19 and 20.

[edit] Compile Command

gcc example0.c -lsam -lpthread -o example0

[edit] Download