fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Slot
  5. {
  6. int min;
  7. int max;
  8. }Slot;
  9.  
  10. typedef struct Table
  11. {
  12. Slot* *array;
  13. int size;
  14. }Table;
  15.  
  16. Table* createTable( int size )
  17. {
  18. Table* table = malloc( sizeof( Table ) );
  19.  
  20. if( !table )
  21. return NULL;
  22.  
  23. table->array = ( Slot(*)[size] ) malloc( size * size * sizeof( Slot ) );
  24.  
  25. if( !(table->array) )
  26. return NULL;
  27.  
  28. table->size = size;
  29.  
  30. return table;
  31. }
  32.  
  33. void foo( int arr[], int size )
  34. {
  35. Table* table = createTable( size );
  36.  
  37. if( table == NULL )
  38. {
  39. printf( "Out of memory" );
  40. return;
  41. }
  42.  
  43. int i;
  44.  
  45. for( i = 0; i < size; ++i )
  46. (table->array[i][i]).min = (table->array[i][i]).max = arr[i];
  47. }
  48.  
  49. int main()
  50. {
  51. int arr[] = {4,5,1,5,7,6,8,4,1};
  52. int size;
  53.  
  54. size = sizeof( arr ) / sizeof( *arr );
  55.  
  56. foo( arr, size );
  57.  
  58. return 0;
  59. }
Runtime error #stdin #stdout 0.02s 1804KB
stdin
Standard input is empty
stdout
Standard output is empty