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

Recommended Answers

All 8 Replies

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;
}

Erm is there other way to do rather than structures

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.

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

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.

Anyone please Help

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.