SpaceNugget
SpaceNugget

Reputation: 129

How to declare a matrix with two columns and unknown number of rows in C

I need to create a matrix with 2 columns and unknown number of rows. I know I have to use malloc but I can't find how to declare such matrix. it should hold integers in the first column and doubles in the second. How do I do that?

Upvotes: 0

Views: 201

Answers (1)

Ed Heal
Ed Heal

Reputation: 59997

struct item {

  int i;
  double d;
};

struct item matrix = malloc(sizeof(struct item) * number_of_rows)

matrix[0].i = 544343;
matrix[0].d = 0.3434343;

Is that the code you are looking for?

Upvotes: 2

Related Questions