daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Dec 17th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define FILE_TXT "file.txt"
  4. #define N 4
  5. #define M 5
  6.  
  7. void zapis_pliku(int n, int m)
  8. {
  9.     FILE* fi;
  10.     if ((fi=fopen(FILE_TXT, "w"))!=NULL)    printf("Utworzono plik tekstowy %s\n", FILE_TXT);
  11.     int y;
  12.     for(int i=0;i<n;i++)
  13.     {
  14.         for(int j=0;j<m;j++)
  15.         {
  16.             y=rand()%10;
  17.             fprintf(fi,"%d,",y);
  18.  
  19.         }
  20.         fprintf(fi,"\n");
  21.     }
  22.  
  23.     fclose(fi);
  24. }
  25.  
  26. void odczyt_pliku(int n, int m)
  27. {
  28. FILE* fa;
  29.     char c;
  30.     char **tab;
  31.     if ((fa=fopen(FILE_TXT, "r"))!=NULL)    printf("Wyswietlono plik tekstowy %s\n", FILE_TXT);
  32.  
  33.     int wier=2*M+1;
  34.     int col=N;
  35.     tab=(char**)malloc(wier*sizeof(char*));
  36.     for(int i=0; i<wier; i++)
  37.         tab[i]=(char*)malloc(col*sizeof(char));
  38.     for(int j=m+1;j>=0;j--)
  39.     {
  40.         for(int i=n+1;i>=0;i--)
  41.         {
  42.  
  43.             c=fgetc(fa);
  44.             printf("%c",c);
  45.  
  46.         }
  47.  
  48.     }
  49.  
  50.     fclose(fa);
  51.  
  52. }
  53.  
  54. int main()
  55. {
  56.  
  57.     zapis_pliku(N,M);
  58.     odczyt_pliku(N,M);
  59.  
  60.     return 0;
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top