Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays 1

Status
Not open for further replies.

welshspoon

Technical User
Dec 14, 2002
34
GB
Hiya!

I'm just starting to learn C and I've run into a few problems.

I need to allow the user to enter a series or values into an array with no defined size, and when they enter a 0 no more values can be entered.

Is there anyway of doing this?

Thanks in advance for your help
 
Option 1: create a singly linked list and grab all the data. When the user has finished, create an array using malloc and dump all the values in the SLL into it.

Option 2: malloc an array with some high tide value (say 10). When the user enters more numbers than you have allocated in the high tide value, add 10 to the high tide value and reallocate the array. You will need to keep a count of how many values have been entered as well as the high tide value.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top