Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/09/2014, 13:55
Metus
 
Fecha de Ingreso: agosto-2014
Ubicación: Chile
Mensajes: 5
Antigüedad: 9 años, 8 meses
Puntos: 0
Violación de segmento con matriz

Hola a todos, espero me puedan ayudar.

Estoy intentando llenar una matriz de [5][5] de forma aleatoria y que luego imprima el resultado.
El código es el siguiente.

Código C:
Ver original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void introduce(int matriz[][5]);
  5. void leer(int matriz[][5]);
  6.  
  7. int main(int argc, char const *argv[])
  8. {
  9.     int matriz[5][5];
  10.  
  11.     introduce(matriz);
  12.     leer(matriz);
  13.  
  14.     return 0;
  15. }
  16.  
  17. void introduce(int matriz[][5]){
  18.     int i, j;
  19.  
  20.     srand(time(NULL));
  21.  
  22.     for (i = 0; i < 5; ++i){
  23.         for (j = 0; j < 5; ++j){
  24.             matriz[i][j] = rand()%10;
  25.         }
  26.     }
  27. }
  28.  
  29. void leer(int matriz[][5]){
  30.     int i, j;
  31.  
  32.     for (i = 0; i < 5; ++i){
  33.         for (j = 0; j < 5; ++i){
  34.             printf("%i ", matriz[i][j]);
  35.         }
  36.         printf("\n");
  37.     }
  38. }

Al compilar no me manda ningún error
Código BASH:
Ver original
  1. metus@metus ~ $ gcc -o matriz matriz.c
  2. metus@metus ~ $

pero al ejecutarlo me salen estos resultados:
Código BASH:
Ver original
  1. metus@metus ~ $ ./matriz
Código Otro:
Ver original
  1. 0 6 0 0 9 32767 1496751813 32767 0 0 0 1761281253 0 32767 0 32767 -1759235576 0 -1759231058 32767 -1759230922 32767 -1759230773 32767 -1759229309 32767 -1759229037 32767 -1759228731 32767 -1759228555 32767 -1759228461 32767 -1759228264 32767 -1759228102 32767 -1759227967 0 16 0 100 0 5 0 0 0 12 0 1000 0 31 0 0 -1920327830 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1769108577 1397052255 1414415687 1212370517 1027885392 1028605518 1769109861 1163132977 1647275625 1263488835 1697998177 808530993 825636400 1431327829 926104900 1634296933 1936020015 1852397359 1414418243 1798254640 1162108755 995250002 1397489779 859517232 1030320186 825245039 876438627 976302139 1633892915 859666287 993079357 2053600302 708456755 993079357 1819553322 976302907 859517232 993079357 809335404 2053254698 708456755 825244978 1650811950 708456755 993079357 1918989102 708456755 993079357 2050436650 774519345 993079357 1886216750 708457779 993079357 1835169838 708457779 825245030 1987259946 892549937 809334883 1831742010 859517232 1031170925 708457779 993079357 879783214 976565051 993079357 1718837550 774519349 993079357 1768711726 708457779 892549937 809329783 1663969850 892549937 809334894 1865296442 909327152 809329505 1831742010 859516976 1029927021 774519350 909327152 809328999 2016291386 1230128223 1764713065 1966029417 762869102 1129272159 2036689711 1397966163 1701654380 796420462 1886221359 1380275029 1599296588 1852793703 1634741876 1263748420 1937077349 1969318957 1953723747 1869900659 1697594707 792360044 1831822701 795631971 980314466 792358505 1936026977 1162084467 1819631974 1230258499 1831822701 1735357040 1852139876 3681606 942751044 1966030152 1969317477 1145897064 1815957071 1634100580 1313818963 133Violación de segmento

Espero me puedan ayudar.