Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 23-08-2008, 10:13 AM   #1 (permalink)
Save the WORLD !!!
 
Kulz's Avatar
 
Join Date: Apr 2008
Posts: 35
Default Doubt In C


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....
__________________
Save the WORLD
Kulz is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 23-08-2008, 11:05 AM   #2 (permalink)
Human Spambot
 
Join Date: Jan 2007
Location: Lat 28.38°N , Longt 77.13°E
Posts: 2,431
Default Re: Doubt In C

Please make your query more clear.
ThinkFree is offline  
Old 23-08-2008, 12:51 PM   #3 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: Doubt In C

afair you may have to realloc to increase memory. Just google for 'realloc c'
__________________
Life is too short. Have fun.
ilugd is offline  
Old 23-08-2008, 02:51 PM   #4 (permalink)
Tux Fan
 
shaunak's Avatar
 
Join Date: Mar 2004
Location: Mumbai
Posts: 1,188
Default Re: Doubt In C

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

In C++ I would use vectors.
__________________
Cheers
Shaunak
Feel free to PM/email me.

Visit me sometime @ http://shaunak.ws
shaunak is offline  
Old 23-08-2008, 03:47 PM   #5 (permalink)
Save the WORLD !!!
 
Kulz's Avatar
 
Join Date: Apr 2008
Posts: 35
Default Re: Doubt In C

Quote:
Originally Posted by ThinkFree View Post
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()

Quote:
Originally Posted by shaunak View Post
You can to use a pointer and malloc() or this: http://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..
__________________
Save the WORLD

Last edited by Kulz; 23-08-2008 at 03:49 PM. Reason: Automerged Doublepost
Kulz is offline  
Old 23-08-2008, 05:23 PM   #6 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Doubt In C

If you don't want to use malloc(), then AFAIK, you can't create dynamically expanding arrays..
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 25-08-2008, 06:32 AM   #7 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Doubt In C

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.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 25-08-2008, 06:53 PM   #8 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Doubt In C

Quote:
Originally Posted by Kulz
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.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 25-08-2008, 07:47 PM   #9 (permalink)
Save the WORLD !!!
 
Kulz's Avatar
 
Join Date: Apr 2008
Posts: 35
Default Re: Doubt In C

Thank you guys for your suggestions...I'll go forward and learn pointers and dynamic allocation.... Thanks again..
__________________
Save the WORLD
Kulz is offline  
Old 29-09-2008, 08:53 PM   #10 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2008
Posts: 6
Default Re: Doubt In C

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

then i will try to solve ur problem................
surajkumarjha2002 is offline  
Old 29-09-2008, 10:05 PM   #11 (permalink)
Human Spambot
 
Join Date: Jan 2007
Location: Lat 28.38°N , Longt 77.13°E
Posts: 2,431
Default Re: Doubt In C

^^Don't you think you were too late in replying to the query?
ThinkFree is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RAM doubt shariq_pj Hardware Q&A 3 16-11-2006 12:05 AM
one doubt please mayneu QnA (read only) 5 07-10-2006 01:05 PM
I have a doubt fibermanco QnA (read only) 8 17-09-2006 12:30 AM
VB Doubt ? Dipen01 QnA (read only) 12 22-08-2005 12:46 PM
A little doubt rakee QnA (read only) 6 18-04-2005 03:48 PM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:10 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2