954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HELP dynamically created and resized arrays

Hey everyone new to the board and in a bit of bother.

I've got this assignment thats been plaging me for two weeks but i can't do this one bit as i just don't get it.

I've got to write a programme that takes data in from a file and inserts them into arrays. the array is set up through a strut.

I should then be able to add,delete,amend,or list the data on the screen in certain orders.

now all this is O.K. i understand all this and can do this but i don't know how to dynamically resized an array if the array gets full ! :confused:
I've been scraching my head now for two weeks and nothing is going on will some one please take the time too explain how to implement this i would be very greatfull.:cheesy: :cheesy:

All those pointers get me confused PLUS not aloud to use VECTORS or old C malloc etc

thanks steve

p.s. great board

toomuchfreetime
Light Poster
29 posts since Nov 2006
Reputation Points: 10
Solved Threads: 1
 

Like you start with
int size = 10;
int *array = new int[size];

And to make it bigger, int *bigger = new int[size+10];
// some stuff
delete [ ] array;
array = bigger;

What goes in "some stuff" is an exercise for the reader ;)

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Sorry now but still not sure how to implement it into my programme:confused: rough example follows::::



#define MAX_PERSONS 100
 
 
struct array
{
    string name;
    
    int account; 
    
    double balance;
    
};
 
typedef  array ARRAY;   
 
 
ARRAY valu[MAX_PERSONS];
 
void add_account(ARRAY package_info[]);
 
 
int menu();
 
{
case 1 :   add_account(valu);
               break;
 
case 2 :   delete(valu);
               break;
 
case 3 :    amend(valu):
                break;
 
case 4 :    list(valu);
                break;
 
}

int menu();
{
 
BLA BLA BLA BLA
}
 
 
void add_account(ARRAY package_info[])
{
 
search array for freespace
 
   if no free space RESIZE
 
  else input data
 
 
}
toomuchfreetime
Light Poster
29 posts since Nov 2006
Reputation Points: 10
Solved Threads: 1
 

Assume that the array is a fixed size (ie, a regular array), and write some code to put data into it.

Turning it into a variable length array (once you've done that) is only a few lines of code.

At least it allows you to focus on one issue at a time.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You