Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int **GetMatrixFile(const char filename[], const int strings, const int columns)
- {
- FILE *file;
- int **matrix;
- fopen_s(&file, filename, "r");
- if (file != NULL)
- {
- printf("Матрица %c(%d x %d):n",
- filename[0], strings, columns);
- matrix = (int**)malloc(strings * sizeof(int*));
- if (matrix != NULL)
- {
- for (int i = 0; i < strings; ++i)
- {
- printf("|");
- matrix[i] = (int*)malloc(columns * sizeof(int));
- if (matrix[i] != NULL)
- {
- for (int j = 0; j < columns; ++j)
- {
- fscanf_s(file, "%d", &matrix[i][j]);
- printf("%3d ", matrix[i][j]);
- }
- }
- else exit(EXIT_FAILURE);
- printf("|n");
- }
- }
- else exit(EXIT_FAILURE);
- fclose(file);
- }
- else exit(EXIT_FAILURE);
- return matrix;
- }
Add Comment
Please, Sign In to add comment