You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
6 years ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
#define NUMBER_OF_ROWS 10
|
||
|
#define NUMBER_OF_COLUMNS 10
|
||
|
|
||
|
int readArrayFromFile(int rows, int columns, double array[rows][columns]);
|
||
|
void printPointsArray(int rows, int columns, double array[rows][columns]);
|
||
|
void init(int pointsArrayRows, int pointsArrayColumns, double pointsArray[pointsArrayRows][pointsArrayColumns]);
|
||
|
|
||
|
int main(int argc, char const *argv[]){
|
||
|
double pointsArray[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS];
|
||
|
int row;
|
||
|
|
||
|
init(NUMBER_OF_ROWS, NUMBER_OF_COLUMNS, pointsArray);
|
||
|
printPointsArray(NUMBER_OF_ROWS, NUMBER_OF_COLUMNS, pointsArray);
|
||
|
|
||
|
printf("Done! Press any key to exit.\n");
|
||
|
scanf("%d", &row);
|
||
|
}
|
||
|
|
||
|
int readArrayFromFile(int rows, int columns, double array[rows][columns]){
|
||
|
FILE *pointsBinaryFile;
|
||
|
pointsBinaryFile = fopen("data.bin","rb");
|
||
|
|
||
|
if(fread(array, sizeof(double), rows * columns, pointsBinaryFile) != rows * columns) {
|
||
|
if(feof(pointsBinaryFile))
|
||
|
printf("There were usefull info after the end of file.\n");
|
||
|
else
|
||
|
printf("File read error.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
fclose(pointsBinaryFile);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void printPointsArray(int rows, int columns, double array[rows][columns]){
|
||
|
int row, column;
|
||
|
|
||
|
for (row=0; row<rows; ++row){
|
||
|
for (column=0; column<columns; ++column){
|
||
|
printf("pointsArray[%d][%d] = %f\n", row, column, array[row][column]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void init(int pointsArrayRows, int pointsArrayColumns, double pointsArray[pointsArrayRows][pointsArrayColumns]){
|
||
|
int row, column;
|
||
|
|
||
|
if (readArrayFromFile(pointsArrayRows, pointsArrayColumns, pointsArray)){
|
||
|
printf("Failed... Press any key to exit.\n");
|
||
|
scanf("%d", &row);
|
||
|
exit(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|