473,385 Members | 1,973 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,385 software developers and data experts.

passing multiple-index array to function


this should be trivial, yet i can't find it in a tutorial.

int AAA[12][234];
int BBB[98][2478];

i want to call f(AAA,12,234) and f(BBB,98,2478).

how should f be declared?

int f( huh?, int ll, int rr)
{
int a,b;
for( a=...
for( b=...
huh2?[a][b] = 234.4;
return 0;
}

i'm starting to get the impression that f() can't use int **huh,
because that's pointers to pointers, whereas AAA is 12*234
contiguous ints. i really do want to pass f the address of ll*rr
contiguous ints so i don't have to "hardcode" for each array
size i might use.

what's the right way? i won't be doing 3 indexes, but is
the generalization to 3 obvious?

i gotta be missing something.

j.
--
Jay Scott 512-835-3553 gl@arlut.utexas.edu
Head of Sun Support, Sr. Operating Systems Specialist
Applied Research Labs, Computer Science Div. S224
University of Texas at Austin
Feb 3 '06 #1
4 1952
Jay G. Scott wrote:
this should be trivial, yet i can't find it in a tutorial.

int AAA[12][234];
int BBB[98][2478];

i want to call f(AAA,12,234) and f(BBB,98,2478).


int f(int n, int m, int a[n][m]); /* C99 prototype */
Feb 3 '06 #2
In article <if******************@newsread2.news.atl.earthlink .net>,
Martin Ambuhl <ma*****@earthlink.net> wrote:
Jay G. Scott wrote:
this should be trivial, yet i can't find it in a tutorial.

int AAA[12][234];
int BBB[98][2478];

i want to call f(AAA,12,234) and f(BBB,98,2478).


int f(int n, int m, int a[n][m]); /* C99 prototype */

thank you. i have written this in my C manual.

j.
--
Jay Scott 512-835-3553 gl@arlut.utexas.edu
Head of Sun Support, Sr. Operating Systems Specialist
Applied Research Labs, Computer Science Div. S224
University of Texas at Austin
Feb 3 '06 #3
Jay G. Scott wrote:
int AAA[12][234];
int BBB[98][2478];

i want to call f(AAA,12,234) and f(BBB,98,2478).

how should f be declared? <snip> what's the right way?


Is there anything wrong in passing a void *, provided, of course, that
everything is properly documented?
#include <stdio.h>
#include <stdlib.h>

double
sum_int_array_elements(
void *two_dimensional_array_of_ints,
size_t elements);

int main(void) {
int a[3][7] = {
{1, 2, 3, 4, 5, 6, 7},
{1, 2, 3, 4, 5, 6, 7},
{1, 2, 3, 4, 5, 6, 7}
};
int b[9][2] = {
{1, 2}, {1, 2}, {1, 2},
{1, 2}, {1, 2}, {1, 2},
{1, 2}, {1, 2}, {1, 2}
};

printf("sum of elements of a is %g\n", sum_int_array_elements(a, 3 * 7));
printf("sum of elements of b is %g\n", sum_int_array_elements(b, 9 * 2));

return 0;
}

double sum_int_array_elements(void *a, size_t n) {
double sum = 0;
int * p = a;

while (n--) sum += p[n];

return sum;
}

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Feb 3 '06 #4
In article <sl*******************@ID-203069.user.individual.net>,
Pedro Graca <he****@hotpop.com> wrote:
Jay G. Scott wrote:
int AAA[12][234];
int BBB[98][2478];

i want to call f(AAA,12,234) and f(BBB,98,2478).

how should f be declared?<snip>
what's the right way?


Is there anything wrong in passing a void *, provided, of course, that
everything is properly documented?


i left out a lot of detail.
the soln below turns the array into a scaler---it treats all the elements
alike. i'm going to return an array value.
if i lose the information about indexes then i'd have
to do something to assign to a given row and column. i'd rather let
the compiler keep track of the indexes.

j.


#include <stdio.h>
#include <stdlib.h>

double
sum_int_array_elements(
void *two_dimensional_array_of_ints,
size_t elements);

int main(void) {
int a[3][7] = {
{1, 2, 3, 4, 5, 6, 7},
{1, 2, 3, 4, 5, 6, 7},
{1, 2, 3, 4, 5, 6, 7}
};
int b[9][2] = {
{1, 2}, {1, 2}, {1, 2},
{1, 2}, {1, 2}, {1, 2},
{1, 2}, {1, 2}, {1, 2}
};

printf("sum of elements of a is %g\n", sum_int_array_elements(a, 3 * 7));
printf("sum of elements of b is %g\n", sum_int_array_elements(b, 9 * 2));

return 0;
}

double sum_int_array_elements(void *a, size_t n) {
double sum = 0;
int * p = a;

while (n--) sum += p[n];

return sum;
}

--
If you're posting through Google read <http://cfaj.freeshell.org/google>

--
Jay Scott 512-835-3553 gl@arlut.utexas.edu
Head of Sun Support, Sr. Operating Systems Specialist
Applied Research Labs, Computer Science Div. S224
University of Texas at Austin
Feb 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mike M | last post by:
Is it possible? In the parent process, I have a socket that binds, listens and then accepts new connections (which creates new sockets in the process). I want to be able to pass some of these new...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
3
by: ben | last post by:
Hi guyz, I am developing a website using php.This website involves dealing with forms which span over multiple pages. I want data obtained from 1 form to be available after 3-4 pages. This...
10
by: Joseph S. | last post by:
Hi, How do I pass a string from one call to a php block to another call in the same page but from another form? Here's my full php code: I'm using two forms in the same page. A hidden field...
1
by: Maria | last post by:
Hello! I am new to Crystal reports an I have problems passing parameters form outside to Crystal report an creating a report with data from more than one table This is the problem: I have to...
2
by: Paul Hale | last post by:
Hi all, being new to c# I'm trying to find the best way of passing multiple records to insert into a sql database via a stored procedure. I'm using visual studio 2005 RC SQL server 2005 and C# of...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
4
by: tbayse | last post by:
Hello, I have a question about making multiple selection queries in Access. I am running windows XP and Access 2003. Up until this point I had a form where a user would make single selections from...
7
by: DazlerD | last post by:
Hi everyone I am writting an application in VB.NET to print orders. The orders are shown on screen in a listview and the user can select individual orders/range of orders to print. This Access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.