fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define K 4
  4. #define W 4
  5.  
  6. void swap( int (*m)[5], const int w1, const int w2)
  7. {
  8.  
  9. int (*temp)[5] = m[w1];
  10. m[w1] = m[w2];
  11. m[w2] = temp;
  12.  
  13. }
  14.  
  15. int main( void ) {
  16.  
  17. int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
  18.  
  19. swap( m, 0, 2); //zamień wiersz 0 z 2
  20.  
  21. for( int i = 0; i < W; ++i ) {
  22.  
  23. for( int j = 0; j < K; ++j ) printf("%3d ", m[i][j]);
  24.  
  25. }
  26.  
  27. return 0;
  28.  
  29. }
Compilation error #stdin compilation error #stdout 0s 9296KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘swap’:
prog.c:9:20: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
   int (*temp)[5] = m[w1];
                    ^
prog.c:10:9: error: assignment to expression with array type
   m[w1] = m[w2];
         ^
prog.c:11:9: error: assignment to expression with array type
   m[w2] = temp;
         ^
prog.c: In function ‘main’:
prog.c:17:3: warning: braces around scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
   ^~~
prog.c:17:3: note: (near initialization for ‘(anonymous)[0]’)
prog.c:17:32: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                ^
prog.c:17:32: note: (near initialization for ‘(anonymous)[0]’)
prog.c:17:34: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                  ^
prog.c:17:34: note: (near initialization for ‘(anonymous)[0]’)
prog.c:17:36: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                    ^
prog.c:17:36: note: (near initialization for ‘(anonymous)[0]’)
prog.c:17:38: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                      ^
prog.c:17:38: note: (near initialization for ‘(anonymous)[0]’)
prog.c:17:3: warning: braces around scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
   ^~~
prog.c:17:3: note: (near initialization for ‘(anonymous)[1]’)
prog.c:17:45: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                             ^
prog.c:17:45: note: (near initialization for ‘(anonymous)[1]’)
prog.c:17:47: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                               ^
prog.c:17:47: note: (near initialization for ‘(anonymous)[1]’)
prog.c:17:49: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                 ^
prog.c:17:49: note: (near initialization for ‘(anonymous)[1]’)
prog.c:17:3: warning: braces around scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
   ^~~
prog.c:17:3: note: (near initialization for ‘(anonymous)[2]’)
prog.c:17:54: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                      ^
prog.c:17:54: note: (near initialization for ‘(anonymous)[2]’)
prog.c:17:56: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                        ^
prog.c:17:56: note: (near initialization for ‘(anonymous)[2]’)
prog.c:17:58: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                          ^
prog.c:17:58: note: (near initialization for ‘(anonymous)[2]’)
prog.c:17:60: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                            ^
prog.c:17:60: note: (near initialization for ‘(anonymous)[2]’)
prog.c:17:3: warning: braces around scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
   ^~~
prog.c:17:3: note: (near initialization for ‘(anonymous)[3]’)
prog.c:17:67: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                                   ^
prog.c:17:67: note: (near initialization for ‘(anonymous)[3]’)
prog.c:17:69: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                                     ^
prog.c:17:69: note: (near initialization for ‘(anonymous)[3]’)
prog.c:17:71: warning: excess elements in scalar initializer
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                                                                       ^
prog.c:17:71: note: (near initialization for ‘(anonymous)[3]’)
prog.c:17:19: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
   int ( *m )[K] = ( int*[] ){ {3,5,1,4}, {0,0,0,0}, {9,9,1,9}, {0,0,0,0} };
                   ^
prog.c:19:9: warning: passing argument 1 of ‘swap’ from incompatible pointer type [-Wincompatible-pointer-types]
   swap( m, 0, 2);  //zamień wiersz 0 z 2
         ^
prog.c:6:6: note: expected ‘int (*)[5]’ but argument is of type ‘int (*)[4]’
 void swap( int (*m)[5], const int w1, const int w2)
      ^~~~
stdout
Standard output is empty