# Doubt In C



## Kulz (Aug 23, 2008)

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....


----------



## ThinkFree (Aug 23, 2008)

Please make your query more clear.


----------



## ilugd (Aug 23, 2008)

afair you may have to realloc to increase memory. Just google for 'realloc c'


----------



## shaunak (Aug 23, 2008)

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

In C++ I would use vectors.


----------



## Kulz (Aug 23, 2008)

ThinkFree said:


> 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()



shaunak said:


> 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 (Aug 23, 2008)

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


----------



## QwertyManiac (Aug 25, 2008)

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 (Aug 25, 2008)

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 (Aug 25, 2008)

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


----------



## surajkumarjha2002 (Sep 29, 2008)

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

then i will try to solve ur problem................


----------



## ThinkFree (Sep 29, 2008)

^^Don't you think you were too late in replying to the query?


----------

