Jan 12, 2011 at 5:56am UTC
Hi,
I am trying to build a 2D matrix and fill the first row and column with zeros. However, I want to do this in a function, but I have huge problems doing this.
The following code works, but this is hardcoded. Alternative solutions are also welcome :)
#include <iostream>
#include <string>
using namespace std;
void fill_matrix(int L1,int L2,int array[][6]) {
for (int i=0;i<L1;i++)
{
array[i][0] = 0;
}
for (int j=0;j<L2;j++)
{
array[0][j] = 0;
}
}
int main() {
int L1,L2;
string seq1,seq2;
seq1 = "actgc";
seq2 = "agtgt";
L1 = seq1.size()+1;
//L2 = seq2.size()+1;
L2 = 6;
int M[6][6];
fill_matrix(L1,L1,M);
return 0;
}
Jan 12, 2011 at 7:01am UTC
1 2 3
int test2[2][2] = { {0} };
std::copy(test2[0], test2[0] + 4, std::ostream_iterator<int >(cout, ", " ));
cout<<endl;
sorry, I forgot to change the contents of test2
if you want to fill the array with another number
1 2 3 4
int test2[2][2];
std::fill(test2[0], test2[0] + 4, 10);
std::copy(test2[0], test2[0] + 4, std::ostream_iterator<int >(cout, ", " ));
cout<<endl;
Last edited on Jan 12, 2011 at 4:16pm UTC