Test Foro de elhacker.net SMF 2.1

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 (cpp) [Seleccionar]

# include <iostream>
# include <conio2.h>
# include <stdio.h>
# include <windows.h>

using namespace std;
 
int main()
{
   FILE *fichero;
   int i,j, matriz[12][10];

           /* inicializa matriz a 0 */
   for (i = 0; i < 12; i++)
      for (j = 0; j < 5; j++)
    matriz[i][j] = 0;

   fichero = fopen("C:/ventas.txt","r");
   if (fichero==NULL)
   {
      printf( "No se puede abrir el fichero.\n" );
      system("pause");
      exit (EXIT_FAILURE);
   }
   i = 0;
   while (1)
   {
      if (feof(fichero))
    break;
      fscanf (fichero, "%d %d %d %d %d\n", &matriz[i][0], &matriz[i][1], &matriz[i][2], &matriz[i][3], &matriz[i][4]);
      i++;
   }
   fclose(fichero);

   printf( "Contenido del fichero:\n" );
   for (i = 0; i < 12; i++)
   {
      for (j = 0; j < 5; j++)
      { 
      printf ("%d ", matriz[i][j]);
       
      }
      printf ("\n");
   }
   system ("PAUSE");
   return EXIT_SUCCESS;
}

Título: Re: Lectura de una matriz en un archivo
Publicado por: MeCraniDOS en 13 Mayo 2014, 23:00 PM
Código (cpp) [Seleccionar]
#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