przy pomocy takiego kodu12
2 1 1
4.000000
15 5 5
2.000000 3.000000 4.000000 1.000000 2.000000
-1.000000 2.000000 0.000000 2.000000 3.000000
2.000000 3.000000 4.000000 1.000000 0.000000
2.000000 3.000000 1.000000 4.000000 8.000000
3.000000 2.000000 4.000000 -1.000000 -2.000000
16 4 4
3.000000 2.000000 1.000000 -1.000000
0.000000 5.000000 2.000000 3.000000
1.000000 2.000000 0.000000 2.000000
0.000000 1.000000 2.000000 4.000000
17 3 3
0.000000 2.000000 1.000000
3.000000 -1.000000 2.000000
4.000000 0.000000 1.000000
18 5 5
3.000000 2.000000 0.000000 1.000000 3.000000
-2.000000 4.000000 1.000000 2.000000 1.000000
0.000000 -1.000000 0.000000 1.000000 -5.000000
-1.000000 2.000000 0.000000 -1.000000 2.000000
0.000000 0.000000 0.000000 0.000000 2.000000
19 6 6
0.000000 1.000000 2.000000 3.000000 4.000000 5.000000
6.000000 7.000000 8.000000 9.000000 10.000000 11.000000
12.000000 13.000000 14.000000 15.000000 16.000000 17.000000
18.000000 19.000000 20.000000 21.000000 22.000000 23.000000
24.000000 25.000000 26.000000 27.000000 28.000000 29.000000
30.000000 31.000000 32.000000 33.000000 34.000000 35.000000
20 3 2
-1.000000 3.000000 0.000000
4.000000 -2.000000 0.000000
5.000000 0.000000 0.000000
21 2 2
-3.000000 2.000000
-4.000000 1.000000
22 2 4
10.000000 10.000000
1000.000000 10.000000
23 1 1
100.000000
24 2 2
10.000000 20.000000
30.000000 40.000000
25 3 3
1.000000 2.000000 3.000000
4.000000 5.000000 6.000000
7.000000 8.000000 9.000000
Kod: Zaznacz cały
void Func_f() //Load matrices from the file
{
int i,j,k,m,how_many;
char filename[20];
int choosing_filename; //0 for proper choice, 1 for illegal character, 2 for exit
char bin;
int in1,in2,in3;
float fl1,fl2,fl3;
printf("You can load file which contains all the matrices.
");
printf("You must choose the name of the existing file which is in actual directory.
");
//Show_actual_directory();
printf("Warning: matrices in memory may be overwritten!");
//choose the filename
Choose_the_filename(filename, &choosing_filename);
//load the matrices from the file
if (choosing_filename==2)
{
printf("You have decided to abandon the process of loading matrices from the file.");
}
else
{
fp = fopen(filename,"r");
if (fp==NULL)
{ //if the file was not opened
printf("The problem has occured during opening of the file. Probably the file does not
exist.");
}
else
{ //if the file is opened properly
printf("You have properly chosen the name of the source file.");
//count how many matrices there are
how_many = 0;
fscanf(fp,"%d
",&how_many); //read number of owned matrices
//read matrices
for (i=0;i<how_many;i++)
{
//fscanf(fp,"%d %d %d",&m,&(matrix[m].sizea),&(matrix[m].sizeb)); <- improper reading
fscanf(fp,"%d %d %d",&in1,&in2,&in3);
m = in1; matrix[m].sizea = in2; matrix[m].sizeb = in3;
// printf("(%d %d %d)[%d %d %d] ",in1,in2,in3,m,matrix[m].sizea,matrix[m].sizeb); system("pause");
for (j=0;j<matrix[m].sizea;j++)
{
for (k=0;k<matrix[m].sizeb;k++)
{
if (k!=0) fprintf(fp," ",&bin); //read spacebar
fscanf(fp,"%f",&fl1); //read exact element to the matrix
// if (i>2) {printf("{%f}",fl1);system("pause");}
matrix[m].values[j][k] = fl1;
}
fprintf(fp,"
",&bin);
}
}
}
fclose(fp);
}
}
Kod: Zaznacz cały
18 5 5
3.000000 2.000000 0.000000 1.000000 3.000000
Pozdro!
PS. Juz rozwiązałem ten problem, ale w zupełnie inny sposób. Dalej nie wiem, co jest nie tak w tym kodzie.