SHARE
TWEET

Untitled

a guest Mar 21st, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdint.h> // for uint8_t
  2. #include <stdlib.h> // for malloc()
  3. #include <string.h> // for memset()
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <assert.h>
  7.  
  8. #include "intarr.h"
  9.  
  10. void print_intarr(intarr_t* ia)
  11. {
  12.   if (ia != NULL )
  13.   {
  14.     printf("Printing intarr of length %d:\n", ia->len);
  15.     for( unsigned i=0; i<ia->len; i++ )
  16.       printf( "%d ", ia->data[i] );
  17.     puts( "(end)" );
  18.   }
  19.   return;
  20. }
  21.  
  22. int main( int argc, char* argv[] )
  23. {
  24.   printf("Creating test_ia\n");
  25.   intarr_t* test_ia = intarr_create( 10 );
  26.   if ( test_ia ==  NULL ) {
  27.     printf("test_ia ==  NULL\n");
  28.     return 1;
  29.   }
  30.   intarr_t* test_ia_copy = NULL;
  31.  
  32.   printf("Populating test_ia\n");
  33.   // Put data in the array
  34.   for( unsigned i=0; i<test_ia->len; i++ )
  35.     test_ia->data[i] = i;
  36.  
  37.   printf("Printing test_ia\n");
  38.   print_intarr( test_ia );
  39.  
  40.   printf("Copying test_ia into test_ia_copy\n");
  41.   test_ia_copy = intarr_copy( test_ia );
  42.  
  43.   printf("Printing test_ia_copy\n");
  44.   print_intarr( test_ia_copy );
  45.  
  46.   printf("Setting first element of test_ia_copy to 99\n");
  47.   intarr_set( test_ia_copy, 0, 99 );
  48.  
  49.   printf("Printing test_ia_copy\n");
  50.   print_intarr( test_ia_copy );
  51.  
  52.   printf("Destroying test_ia\n");  
  53.   intarr_destroy( test_ia );
  54.  
  55.   printf("Destroying test_ia_copy\n");  
  56.   intarr_destroy( test_ia_copy );
  57.  
  58.   return 0;
  59. }
RAW Paste Data
Top