| | |
Passing multi-dimensional array
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 5
Reputation:
Solved Threads: 0
So I'm trying to write a program to simulate Conway's game of life. I thought it'd be cool to declare a class called Cell and use an array of objects instead of an array of ints or bools. My problem is that when I go to compile a function to which I pass a multi-dimensional array of Cell, the compiler yells at me for not giving it a set size. (The size of my board varies). My code...
With a little tinkering and browsing of samples on the internet, I noticed that making it a single dimensional array of ambiguous size works just fine, but soon as its more than one dimension, it says I must declare bounds.
I suspect there may be a way to work around this with pointers, but haven't figured it out yet. Suggestions?
C Syntax (Toggle Plain Text)
void printBoard(Cell board[][], int rows, int cols) { system("cls"); for(int i=0; i<rows; i++) { ... }
With a little tinkering and browsing of samples on the internet, I noticed that making it a single dimensional array of ambiguous size works just fine, but soon as its more than one dimension, it says I must declare bounds.
I suspect there may be a way to work around this with pointers, but haven't figured it out yet. Suggestions?
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: C
- Next Thread: solve equadratric equation in C
| Thread Tools | Search this Thread |
* ansi api append array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation threads unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






