0

HI how can store multiple array into one array

int id[5] = { 1,2,3,4,5,6};
int size[5] = {35,76,85,78};
int PerBox[5] = {12,24,44,54};
double Price[5] = {3.32,6.76, 13.45,6.08,7.8};
int item[200],i;

for(i=0;i<4;i++)
{
 item[i] = {id, size, PerBox, Price};
}

each element should store id, size, perbox, price

and output:

1 , 35, 12, 3.32
...
....
..
Thank

4
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by cse.avinash
0

You would be better served if you created an array of structures.

#include <stdio.h>
#include <stdlib.h>

struct mys
{
  int id, size, PerBox;
  double Price;
};

int main()
{
  struct mys thes[5];
  return 0;
}
0

Erm is there other way to do rather than structures

Yes but why would you? A structure is made to host many different variables in one nice neat (pardon the word usage) structure.

0

Becuz I don't know how to implement. Can u show me other way?

0

Becuz I don't know how to implement. Can u show me other way?

Not without thinking of some obscure, confusing and probably non-portable way...Maybe someone else can think of a simple way to handle this problem.

0

Becuz I don't know how to implement. Can u show me other way?

you can also do it by using a two dimensional array but it has limitations as it will only store the data of a same type.
it will be stored as you are storing something in a table.

Edited by YAMNA MIDHAT: n/a

0

structure is good option, you should learn it but array of pointers can also be used....

Edited by cse.avinash: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.