-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlefile.cpp
More file actions
101 lines (90 loc) · 1.66 KB
/
handlefile.cpp
File metadata and controls
101 lines (90 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;
int R1,C1,R2,C2;
int **mat1,**mat2;
void findinput(){
//return_package = new int*[3];
//int *dimensions;
//dimensions = new int[4];
//int **mat1;
//int **mat2;
ifstream file;
file.open("input.txt");
string buffer;
int r1=0,r2=0;
bool matrix1 = true;
/**Counting rows*/
while(getline(file,buffer)){
if(buffer.length()==0){
matrix1 = false;
continue;
}
switch(matrix1){
case true:
r1++;
break;
case false:
r2++;
break;
}
}
//clear buffer
file.clear();
file.seekg(0);
getline(file,buffer);
/** Counting columns*/
int c1=1,c2=1;
for(int i=0;i<buffer.length();i++){
if(buffer[i]==',')
c1++;
}
file.clear();
file.seekg(0);
for(int i=0;i<r1+2;i++){
getline(file,buffer);
}
for(int i=0;i<buffer.length();i++){
if(buffer[i]==',')
c2++;
}
/**Setting values to matrix A and matrix B*/
file.clear();
file.seekg(0);
mat1 = new int*[r1];
mat2 = new int*[r2];
for(int i=0;i<r1;i++){
mat1[i] = new int[c1];
getline(file,buffer);
int x=0,count=0,j=0;
for(j=0;j<buffer.length();j++){
if(buffer[j]==','){
mat1[i][count++] = stoi(buffer.substr(x,j-x));
x = j+1;
}
}
mat1[i][count] = stoi(buffer.substr(x,j-x));
}
cout<<endl;
getline(file,buffer);
for(int i=0;i<r2;i++){
mat2[i] = new int[c2];
getline(file,buffer);
int x=0,count=0,j=0;
for(j=0;j<buffer.length();j++){
if(buffer[j]==','){
mat2[i][count++] = stoi(buffer.substr(x,j-x));
x = j+1;
}
}
mat2[i][count] = stoi(buffer.substr(x,j-x));
}
file.close();
R1 = r1;
C1 = c1;
R2 = r2;
C2 = c2;
}