Thread: Calling functions within functions

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    63

    Calling functions within functions

    I have two functions. I have 2 arrays in int main. Now I need to pass both arrays individually to these two functions. Everything is fine with the first function. On the second function, I am calling the first function within this function. My question is, what do I put in the spot, marked "/*here*/"? The matrices are a and b. I need to let it use whatever array was passed to the function, so I dont know what to put there, or what else can I do?

    I probably didnt explain it well, so let me know if I need to do more explaining. Thanks for help.

    Code:
    int setCardinality(int a[]){
    	
    	int i;
    	int numberElements=1;
    
    	for(i=1;a[i]!=-1;i++){
    		numberElements++;
    		
    	}
    	return (numberElements);
    
    }
    
    void printSet(int a[]){
    
    	int setCardinality(int a[]);
    	
    	int j;
    
    	for(j=0;j<setCardinality(/*here*/);j++){
    		printf("%d,", a[j]);
    	}
    	printf("}\n");
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I may be misunderstanding you here, but is this what you are looking for?
    Code:
    for(j=0;j<setCardinality(a);j++)
    Code:
    for(i=1;a[i]!=-1;i++)
    Is this intentional? Array indexes start at 0, not 1.

    Code:
    int setCardinality(int a[]);
    There's no point for this prototype to exist in the middle of a function block.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  2. Replies: 9
    Last Post: 01-26-2008, 03:12 AM
  3. calling functions: exit and return
    By 911help in forum C Programming
    Replies: 3
    Last Post: 12-28-2007, 01:24 PM
  4. I Need Help Defining and Calling Functions
    By jonbuckets in forum C++ Programming
    Replies: 6
    Last Post: 10-25-2007, 09:46 AM
  5. Calling functions help
    By ForlornOdium in forum C++ Programming
    Replies: 14
    Last Post: 09-29-2003, 08:40 PM