Solved

function prototype

Posted on 2006-10-28
3
258 Views
Last Modified: 2010-04-15
..

int funcZ( int array[][], int k, int b,int  c )

{
... .. .. ..
Funcb(array[x][], k, b);
Funcb(array[][x], k, c);
...

}

int Funcb(int arr[], int k, int d )
{
....
}

b is binary search, but according to my code, array[][]'s first []'s search then other []'s search.. so of course it can not be compiled, how to correct it..
0
Comment
Question by:thefirstfbli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Assisted Solution

by:momi_sabag
momi_sabag earned 250 total points
ID: 17826311
hi

what you want to do simply can not be done
for c, an [] specification means a contiguoes memory that holds x items of the same data type
when you specify [][x], the space you are refering to is not contiguoes, and the compiler can not treat it as a reguler [] type,

what you can do is create a [] from the data and then pass it to the function, for exapmle :
Funcb(array[x][], k, b);

int temp[];
int i;

for (i=0; i<array_size; ++i) {
   temp[i] = array[i][x];
}

Funcb(temp, k, c);


momi
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 17826482
Do you want to do something with 2D array rows and columns? In this case try the following function:

int Funcb(int* arr,     /* pointer to first array member/*
     int step,               /* distance between members/*
     int size,               /* number of elements to handle*/
     int k, int d )         /* your existing parameters - I don't know what they are */
{
    int i;

    for ( i = 0; i < size; i++ )
    {
         // work with *arr
         // move to next element: increment arr to step
    }
}

For example, you have 10*10 array. To handle array row, call Funcb with step = 1. To handle array column, call Funcb with step = 10.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17828233
Correction:
To handle array column, call Funcb with step = 9.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question