D
D
DAN_ON2020-12-04 21:43:42
C++ / C#
DAN_ON, 2020-12-04 21:43:42

How do I write 1 row of a 2D array into a 1D array?

How do I write 1 row of a 2D array into a 1D array? I have a two-dimensional array and I need to write its first line into a one-dimensional array, but I don't know how?

int const COL = 7;
  int const ROW = 6;
  int ar[ROW][COL];
  int al[4];
  for (int i = 0; i < ROW; i++) {
    for (int j = 0; j < COL; j++) {
      ar[i][j] = rand() % 100;
      cout << ar[i][j] << "\t";
    
    }
    cout << endl;
  }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xorknown, 2020-12-04
@DAN_ON

Do not forget that your arrays are of different sizes, and the whole string from ar will not fit into al.
Try to forget about raw arrays and use containers.

for (int i = 0; i < std::size(al); i++) {
    al[i] = ar[0][i];
}

E
entermix, 2016-11-24
@3dben

Well, it's written like this:
Translate into Russian, or guess your login / password / database name? :)

M
Michael, 2016-11-25
@MikeDeblin

Check the permissions on the db_shop database with the admin user in the mysql.db
table
If an error is received, we check the access rights to the database.
Oh, and don't forget to do FLUSH PRIVILEGES; after changing rights.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question