DIGIT-ARC read-only archive · snapshot: July 23, 2026

Doubt In C

11 posts · originally from https://geek.digit.in/community/threads/doubt-in-c.96239/

Kulz
Kulz Original post #1
Aug 23, 2008 at 10:13 AM
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....
T
Aug 23, 2008 at 11:05 AM
Please make your query more clear.
ilugd
ilugd #3
Aug 23, 2008 at 12:51 PM
afair you may have to realloc to increase memory. Just google for 'realloc c'
shaunak
shaunak #4
Aug 23, 2008 at 2:51 PM
You can to use a pointer and malloc() or this: *www.daniweb.com/forums/post66354-4.html

In C++ I would use vectors.
Kulz
Kulz #5
Aug 23, 2008 at 3:47 PM
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..
Garbage
Garbage #6
Aug 23, 2008 at 5:23 PM
If you don't want to use malloc(), then AFAIK, you can't create dynamically expanding arrays..
QwertyManiac
Aug 25, 2008 at 6:32 AM
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
Sykora #8
Aug 25, 2008 at 6:53 PM
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.
Kulz
Kulz #9
Aug 25, 2008 at 7:47 PM
Thank you guys for your suggestions...I'll go forward and learn pointers and dynamic allocation.... Thanks again..
S
Sep 29, 2008 at 8:53 PM
you can use dynamic memory allocation( with pointer ) ,if u wll write down the code....

then i will try to solve ur problem................
T
ThinkFree #11
Sep 29, 2008 at 10:05 PM
^^Don't you think you were too late in replying to the query?