Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. int **GetMatrixFile(const char filename[], const int strings, const int columns)
  2. {
  3. FILE *file;
  4. int **matrix;
  5.  
  6. fopen_s(&file, filename, "r");
  7.  
  8. if (file != NULL)
  9. {
  10. printf("Матрица %c(%d x %d):n",
  11. filename[0], strings, columns);
  12.  
  13. matrix = (int**)malloc(strings * sizeof(int*));
  14. if (matrix != NULL)
  15. {
  16. for (int i = 0; i < strings; ++i)
  17. {
  18. printf("|");
  19.  
  20. matrix[i] = (int*)malloc(columns * sizeof(int));
  21. if (matrix[i] != NULL)
  22. {
  23. for (int j = 0; j < columns; ++j)
  24. {
  25. fscanf_s(file, "%d", &matrix[i][j]);
  26. printf("%3d ", matrix[i][j]);
  27. }
  28. }
  29. else exit(EXIT_FAILURE);
  30.  
  31. printf("|n");
  32. }
  33. }
  34. else exit(EXIT_FAILURE);
  35. fclose(file);
  36. }
  37. else exit(EXIT_FAILURE);
  38.  
  39. return matrix;
  40. }
Add Comment
Please, Sign In to add comment