C - Convert array of elements into 2-d matrix

C - Convert array of elements into 2-d matrix

It might be a stupid question, but I wonder if there is a efficient way to do this.

It might be a stupid question, but I wonder if there is a efficient way to do this.

The situation:

int* array = malloc(n * m * sizeof(int));
//want to convert array into M[n][m]

what I am doing now:

int** M = malloc(n * sizeof(int*));
for(int i = 0; i < n; i++, array += m)
  M[i] = array; 

I don't think the conversion should be this complex. Is there any simple syntax C provided? Can I declare an extern M[n][m] then set its address to the array?

(error handling and memory management in the sample is omitted for simplicity. Just think it as a part of some function.)

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Increased array size. after increaseSize function some arguments of the same array are invalid. C lang

The program takes some txt input from "numbers.txt" file. It first counts the&nbsp;<strong><em>amount</em></strong>&nbsp;of all the numbers (freqCount)in that text file, than reads the file again and with the use of malloc it creates two arrays A and B , of which both have size equal to the&nbsp;<strong>amount</strong>&nbsp;of all the numbers in the text file. So far so good.

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective