Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define FILE_TXT "file.txt"
- #define N 4
- #define M 5
- void zapis_pliku(int n, int m)
- {
- FILE* fi;
- if ((fi=fopen(FILE_TXT, "w"))!=NULL) printf("Utworzono plik tekstowy %s\n", FILE_TXT);
- int y;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- y=rand()%10;
- fprintf(fi,"%d,",y);
- }
- fprintf(fi,"\n");
- }
- fclose(fi);
- }
- void odczyt_pliku(int n, int m)
- {
- FILE* fa;
- char c;
- char **tab;
- if ((fa=fopen(FILE_TXT, "r"))!=NULL) printf("Wyswietlono plik tekstowy %s\n", FILE_TXT);
- int wier=2*M+1;
- int col=N;
- tab=(char**)malloc(wier*sizeof(char*));
- for(int i=0; i<wier; i++)
- tab[i]=(char*)malloc(col*sizeof(char));
- for(int j=m+1;j>=0;j--)
- {
- for(int i=n+1;i>=0;i--)
- {
- c=fgetc(fa);
- printf("%c",c);
- }
- }
- fclose(fa);
- }
- int main()
- {
- zapis_pliku(N,M);
- odczyt_pliku(N,M);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement