| | |
assign elements to a multi-d array
Thread Solved |
•
•
•
•
I need a function that will populate a multidimensional array with a fixed amount of elements. So that only some of the locations contain a distinguishing number for identification.
c Syntax (Toggle Plain Text)
#define ELEMENTS 20 #define ARRAY 5 /* MULTI-DIMENSIONAL */ int multi_ID[ARRAY][ELEMENTS]; ... /* REGULAR ARRAY */ int multi_ID[ELEMENTS];
If you have any questions let me know.
Good luck, LamaBot
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Solved Threads: 0
ok maybe I didn't explain this right the array has a fixed amount of rows and columns. I am supposed to randomly populate the array with 12 objects
I wanted to identify the objects with a number such as 1. the user is then prompted to guess the location of the hidden objects.
I wanted to identify the objects with a number such as 1. the user is then prompted to guess the location of the hidden objects.
C Syntax (Toggle Plain Text)
#define rows 7 #define columns 10 #define max_total 12 void array1( int multi-d[rows][columns], int rows, int columns) { multi-d[rows][columns] = {{0},{0}};/*Initialize all elements to zero*/ /* Populate array???*/ }
Last edited by boujibabe; Mar 4th, 2007 at 11:28 pm.
•
•
•
•
ok maybe I didn't explain this right the array has a fixed amount of rows and columns. I am supposed to randomly populate the array with 12 objects
I wanted to identify the objects with a number such as 1. the user is then prompted to guess the location of the hidden objects.
C Syntax (Toggle Plain Text)
#define rows 7 #define columns 10 #define max_total 12 void array1( int multi-d[rows][columns], int rows, int columns) { multi-d[rows][columns] = {{0},{0}};/*Initialize all elements to zero*/ /* Populate array???*/ }
c Syntax (Toggle Plain Text)
#define elements 100 #define ID 10 void array1(int *multi_d) { int position; /* Put initialization code here (i.e. array = all zeros) */ srand(time(NULL)*rand()); position = rand() % elements; multi_d[position] = ID; }
Make sure you include "time.h" and "stdlib.h" header files. Let me know if you have any problems.
Good luck, LamaBot
Last edited by Lazaro Claiborn; Mar 4th, 2007 at 11:46 pm.
•
•
•
•
ok maybe I didn't explain this right the array has a fixed amount of rows and columns. I am supposed to randomly populate the array with 12 objects
I wanted to identify the objects with a number such as 1. the user is then prompted to guess the location of the hidden objects.
int multi-d[rows][columns]Then fill it with 0's with
for loops.Then loop from 1 to 12 and use LamaBot's idea with
rand() to get a location in the array. Check if the location is zero. If so, load the loop value. If not, get another location. The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
•
•
ok maybe I didn't explain this right the array has a fixed amount of rows and columns. I am supposed to randomly populate the array with 12 objects
I wanted to identify the objects with a number such as 1. the user is then prompted to guess the location of the hidden objects.
C Syntax (Toggle Plain Text)
#define rows 7 #define columns 10 #define max_total 12 void array1( int multi-d[rows][columns], int rows, int columns) { multi-d[rows][columns] = {{0},{0}};/*Initialize all elements to zero*/ /* Populate array???*/ }
Good luck, LamaBot
You know, LamaBot, you don't have to quote every post in their entirety if you aren't going to reference any part of it. And you can edit the quote down to only show the relevant portions you wish to comment on. That would help by not having a 200 line quote with a 3 line reply that has little to do with the quote. Just a thought...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
•
•
You know, LamaBot, you don't have to quote every post in their entirety if you aren't going to reference any part of it. And you can edit the quote down to only show the relevant portions you wish to comment on. That would help by not having a 200 line quote with a 3 line reply that has little to do with the quote. Just a thought...
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Solved Threads: 0
Thanks for the help, First of it hast to be a multi-d array since the rows and columns are predefined.
Second what is wrong with my attempt at initialization to zeros?
Second what is wrong with my attempt at initialization to zeros?
C Syntax (Toggle Plain Text)
byard[row][col] = {{0},{0}};
![]() |
Other Threads in the C Forum
- Previous Thread: Unresolved External Errors
- Next Thread: can anyone help me with writing a magic square program?
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking hardware highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






