Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #define M 4
- #define N 4
- #define LENGTH 100
- void display_exception_message(int code)
- {
- char exception_description [][LENGTH] = {
- "Błąd otwarcia pliku do zapisu.",
- "Błąd zapisu pliku.",
- "Błąd zamknięcia pliku.",
- "Błąd otwarcia pliku do odczytu."
- };
- fprintf(stderr,"%s\n",exception_description[-code-1]);
- }
- int zapis(char *plik, int matrix[M][N])
- {
- FILE *file = NULL;
- srand(time(0));
- file = fopen(plik,"w");
- if(file==NULL)
- return -1;
- int i;
- for(i=0;i<M;i++){
- int j;
- for(j=0;j<N;j++){
- matrix[i][j]=-10+rand()%21;
- fprintf("%4d",matrix[i][j]);
- }
- puts("");
- }
- if(fclose(file)!=0)
- return -3;
- return 0;
- }
- int main ()
- {
- int matrix[M][N];
- int result = zapis("text.txt",matrix);
- if (result<0)
- display_exception_message(result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement