Advertisement
Sayukoo

[Pliki_tekstowe]Zapis z 2wymiarowej tablicy do pliku txt

Nov 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5.  
  6. #define N 5
  7. #define M 5
  8.  
  9. int n,m,i,j;
  10.  
  11. int main()
  12.  
  13. {
  14.     int tab[N][M];
  15.     srand (time(NULL));
  16.     for (i=0; i<N; i++)
  17.     {
  18.         for (j=0;j<M;j++)
  19.         {
  20.             tab[i][j]=rand()%10;
  21.         }
  22.     }
  23.  
  24.  
  25.     FILE *file;
  26.     char nazwa [20];
  27.     scanf ("%s", nazwa);
  28.     file = fopen (nazwa, "w");
  29.     if (file== NULL)
  30.     {
  31.         printf ("Nie udalo sie otworzyc pliku;\n");
  32.     }
  33.     else
  34.     {
  35.         for (int m=0; m<N; m++)
  36.         {
  37.             for ( n=0; n<M;n++)
  38.                 fprintf (file,"%d ",tab[m][n]);
  39.  
  40.                 fprintf (file,"\n");
  41.         }
  42.     }
  43.  
  44.  
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement