Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: deibenK en 13 Mayo 2014, 01:31 am



Título: Lectura de una matriz en un archivo
Publicado por: deibenK en 13 Mayo 2014, 01:31 am
SOLUCIONADO

Código
  1. # include <iostream>
  2. # include <conio2.h>
  3. # include <stdio.h>
  4. # include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.   FILE *fichero;
  11.   int i,j, matriz[12][10];
  12.  
  13.           /* inicializa matriz a 0 */
  14.   for (i = 0; i < 12; i++)
  15.      for (j = 0; j < 5; j++)
  16.    matriz[i][j] = 0;
  17.  
  18.   fichero = fopen("C:/ventas.txt","r");
  19.   if (fichero==NULL)
  20.   {
  21.      printf( "No se puede abrir el fichero.\n" );
  22.      system("pause");
  23.      exit (EXIT_FAILURE);
  24.   }
  25.   i = 0;
  26.   while (1)
  27.   {
  28.      if (feof(fichero))
  29.    break;
  30.      fscanf (fichero, "%d %d %d %d %d\n", &matriz[i][0], &matriz[i][1], &matriz[i][2], &matriz[i][3], &matriz[i][4]);
  31.      i++;
  32.   }
  33.   fclose(fichero);
  34.  
  35.   printf( "Contenido del fichero:\n" );
  36.   for (i = 0; i < 12; i++)
  37.   {
  38.      for (j = 0; j < 5; j++)
  39.      {  
  40.      printf ("%d ", matriz[i][j]);
  41.  
  42.      }
  43.      printf ("\n");
  44.   }
  45.   system ("PAUSE");
  46.   return EXIT_SUCCESS;
  47. }
  48.  
  49.  


Título: Re: Lectura de una matriz en un archivo
Publicado por: MeCraniDOS en 13 Mayo 2014, 23:00 pm
Código
  1. #include <conio2.h>

Eso es caca  :silbar:, deberías evitar su uso

Echa un vistazo a esto

http://foro.elhacker.net/programacion_cc/lo_que_no_hay_que_hacer_en_cc_nivel_basico-t277729.0.html (http://foro.elhacker.net/programacion_cc/lo_que_no_hay_que_hacer_en_cc_nivel_basico-t277729.0.html)

Saludos