Doubt In C

Status
Not open for further replies.

Kulz

Save the WORLD !!!
In an array(static array) of structures, i want to increase the array size later so as to increase a new record in the array. How shall i go forward with it? A simple e.g. would be nice...

Thanks in advance....
 

ilugd

Beware of the innocent
afair you may have to realloc to increase memory. Just google for 'realloc c'
 

shaunak

Tux Fan
You can to use a pointer and malloc() or this: *www.daniweb.com/forums/post66354-4.html

In C++ I would use vectors.
 
OP
Kulz

Kulz

Save the WORLD !!!
Please make your query more clear.

Suppose:-

struct student
{char Name[20];
int Roll;
}n[5];

So to insert a 6th record,a memory allocation in the array of structures has to be incremented..without using malloc()

You can to use a pointer and malloc() or this: *www.daniweb.com/forums/post66354-4.html

In C++ I would use vectors.

can't use malloc() as i want a static array of structures and not a dynamic one..
 
Last edited:

Garbage

God of Mistakes...
If you don't want to use malloc(), then AFAIK, you can't create dynamically expanding arrays..
 

QwertyManiac

Commander in Chief
If what you wanted could be possible directly, why would one go through the pains of reading about and using dynamic arrays?

Pointers aren't hard at all to learn, its best if you first do that.

Or you can do a pseudo technique, by having 2 arrays, but it would make no sense at all.
 

Sykora

I see right through you.
Kulz said:
can't use malloc() as i want a static array of structures and not a dynamic one..

lol. static by definition means that once you declare it, it doesn't change. So you want a 'static' array which is to hold more than you originally declared it to, which just won't work out.

Learn dynamic memory allocation, it's worth the hassle.
 
OP
Kulz

Kulz

Save the WORLD !!!
Thank you guys for your suggestions...I'll go forward and learn pointers and dynamic allocation.... Thanks again..
 

surajkumarjha2002

Right off the assembly line
you can use dynamic memory allocation( with pointer ) ,if u wll write down the code....

then i will try to solve ur problem................
 
Status
Not open for further replies.
Top Bottom