Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-2006, 05:20 PM
hoser2001's Avatar   
hoser2001 hoser2001 is offline
Programmer
 
Join Date: Jul 2006
Posts: 175
Rep Power: 10
hoser2001 is on a distinguished road
Default Dyanmically setting the size of an array

I am given an inpute file that looks like this:

1)N - where N is an integer
2)name1
name2
.
.
nameN-1
nameN
a matrix of values of size NxN

so for example this could be a possible input file:

5
Adam
Bonnie
Clyde
Drake
Emily
0.0 23.7 49.5 9999.9 9999.9
23.7 0.0 16.9 39.4 9999.9
49.5 16.9 0.0 9999.9 53.6
9999.9 39.4 9999.9 0.0 9999.9
9999.9 9999.9 53.6 9999.9 0.0

I need to take this in as an input and be able to:
1) create two arrays of the fashion: float array[n][n] where n is the integer at the beginning
2) create an array to hold the names so something like: char array[n][20]

The problem is I don't know how to do this dynamically, how do I create arrays based on a value I don't know until i suck in the input value????

Any suggestions would be helpful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-12-2006, 09:09 AM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default

Are you using ANSI C++?

For the arrays you can use the split function to create them which will make the size dynamic. Split by linebreak. Lets call this guy array1[].

Next cycle through the data using a for loop. Add array[0] to another array, lets call him dataArray[array[0]][array.Length-1]

Code:
// Using .NET code, convert to whatever - this is just for logic
for (int i=1;i<array.Length;i++) {
dataArray[array[0]][i] = array[i];
}
For the names only create another array and use a function to determine if the value of array[i] is a integer. If not, copy to the function.
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-16-2006, 08:07 PM
falco85 falco85 is offline
Programmer
 
Join Date: Apr 2006
Posts: 105
Rep Power: 10
falco85 is on a distinguished road
Default

The above code looks like it would work but I'm not sure how "valid" that would be.

Are the lengths always fixed?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-17-2006, 05:56 AM
orbital_fox's Avatar   
orbital_fox orbital_fox is offline
Newbie
 
Join Date: Sep 2006
Posts: 26
Rep Power: 9
orbital_fox is on a distinguished road
Default

Dude, u need to use malloc.. Alocate memory, based on the name size, and then store the data there..

But remember, C/C++, will automatically create an array, with all the arguments, if i recall its argv[] .. You could just use that instead, of making your own copy

But malloc is what you need to make dynamic memory management systems..
__________________
Artificial Intelligence and Robotics egnineer
http://fox.zsuatt.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
fread into array position kenna C and C++ 0 08-17-2007 09:03 AM
Othello program!! 24 hours left! siren C and C++ 1 06-14-2007 12:18 PM
Python 2D array question annannienann Python 3 04-23-2007 05:36 PM
Directory Size John PHP Forum 5 08-06-2006 02:02 PM


All times are GMT -5. The time now is 02:05 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads