Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. #define M 4
  7. #define N 4
  8. #define LENGTH 100
  9.  
  10. void display_exception_message(int code)
  11. {
  12. char exception_description [][LENGTH] = {
  13. "Błąd otwarcia pliku do zapisu.",
  14. "Błąd zapisu pliku.",
  15. "Błąd zamknięcia pliku.",
  16. "Błąd otwarcia pliku do odczytu."
  17. };
  18. fprintf(stderr,"%s\n",exception_description[-code-1]);
  19. }
  20.  
  21. int zapis(char *plik, int matrix[M][N])
  22. {
  23. FILE *file = NULL;
  24. srand(time(0));
  25. file = fopen(plik,"w");
  26. if(file==NULL)
  27. return -1;
  28. int i;
  29. for(i=0;i<M;i++){
  30. int j;
  31. for(j=0;j<N;j++){
  32. matrix[i][j]=-10+rand()%21;
  33. fprintf("%4d",matrix[i][j]);
  34. }
  35. puts("");
  36. }
  37. if(fclose(file)!=0)
  38. return -3;
  39. return 0;
  40. }
  41.  
  42. int main ()
  43. {
  44. int matrix[M][N];
  45. int result = zapis("text.txt",matrix);
  46. if (result<0)
  47. display_exception_message(result);
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement