| | |
assign elements to a multi-d array
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






