473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Arrays as arguements

ilikepython
844 Expert 512MB
Hello, I am having touble passing multidimensional arryas as an arguement to a function. This is what I have tried:
Expand|Select|Wrap|Line Numbers
  1. void printarray(char array[5][5]){
  2.     for (int x = 0; x < 5; x++){
  3.         for (int y = 0; y < 5; y++){
  4.             cout << array[x][y];}
  5.         cout << endl;}}
  6.  
  7. int main(){
  8.     char array[5][5];
  9.     printarray(array);
  10.     // rest of program
  11.  
I've also tried declaring the function like: void printarray(char array[][5])
void printarray(char *array[5][5])
void printarray(char *array[][5])

and calling it like: printarray(&array)
printarray(*array)

and none of those work.

The error message is:
Expand|Select|Wrap|Line Numbers
  1.  cannot convert `char (*)[4]' to `char*' for argument `1' to `void printarray(char*)' 
  2.  
Does anybody know what I'm doing wrong?
I'm using Dev C++ on Windows XP.

Thanks in advance.
Apr 7 '07 #1
3 1276
ilikepython
844 Expert 512MB
Never mind, sorry guys.
I got it all figuered out.
Don't need help anymore.
Thanks
Apr 7 '07 #2
rgb
37
pass a pointer of the array as an argument.
Apr 7 '07 #3
JosAH
11,448 Expert 8TB
pass a pointer of the array as an argument.
That's not needed: arrays are passed as a pointer to their first element in every
calue constant. The first element of a two dimensional is a one dimensional
array so a pointer to it looks like this:
Expand|Select|Wrap|Line Numbers
  1. void print(char (*row)[5]) { ... }
Of course for the print function itself there's no way to determine how many
rows the two dimensional matrix has.

kind regards,

Jos
Apr 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Randell D. | last post by:
Folks, I have a large amount of values to store (we're talking tens, if not hundreds of bytes). I need this for a client side application - ignore the security consequences for the moment -...
9
by: Ook | last post by:
I need a function that swaps arguements. This is my function. It works, after calling swapArgs aa now has 321, and bb has 123. My question - did I do it right? Just because it works doesn't mean I...
3
by: junk | last post by:
Hi, Given the following function:- void foo (char *fmt, ...) { } I know how to use va_start, va_end etc to process the parameters but is there an easy way of passing the parameter list...
8
by: Dawn Minnis | last post by:
Hey guys If I have a program (see codeSnippet1) that I compile to be called test.o Then run it as test.o n n 2 3 4 I want the code to be able to strip out the two characters at the start...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
0
by: JeffM | last post by:
If you've seen this before, sorry for the repost, the last post had no replies- and I'm still stuck. Can anyone suggest a way to use a comma delimited text file to supply arguements to a method...
5
by: bg_ie | last post by:
Hi, I'd like to write a function like printf, which takes a string as its first arguement, but then a variable number of arguements after this, based on the contents of the first arguement. ...
2
by: Nike | last post by:
I have a small question w.r.t usage of default arguements in template.. I shall try to elaborate this with an example.. let's say I have some template function , where EntryType is the input for...
1
by: gypsyman58 | last post by:
First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method...
5
by: mmmtacos | last post by:
Hey, I'm pretty new to Java and am having some trouble writing a put() method for one of my programs. The basic idea of it is to have a matrix, made by a multi-dimensional array, then to create the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.