Thread: Passing an array to a function, failed with exit code 1 (Xcode)

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    1

    Passing an array to a function, failed with exit code 1 (Xcode)

    Hello people,

    I'm writing a program (on Xcode, OSX) to find the largest number in an array by passing it to a function. Apparently, the compiler reports no other error except 'failed with exit code 1'. I'm stuck.

    Code:
    #include <stdio.h>
     
    int largest(int array[5],int holder);
    
    int main()
    {
    	int array[5],counter,temp;
    	
    	printf("Enter five numbers to select the largest of them:\n");
    	
    	for(counter=0;counter<5;counter++)
    	{
    		scanf("%d",&array[counter]);
    	}
    	
    	temp=largest(array,5);
    	
    	printf("%d\n",temp);
    }
    
    int largest(int array[], int holder)
    		{
    			int counter,large;
    			large=array[0];
    			
    			for(counter=0;counter<5;counter++)
    			{
    				if(large<array[counter])
    				
    					large=array[counter];
    			}
    			
    			return(large);
    		}
    Can any one suggest what is wrong in the program? A help would be appreciated

  2. #2
    Novice
    Join Date
    Jul 2009
    Posts
    568
    There's a mismatch between the function declaration (prototype) up top and definition down under -- they must match.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    main should return a 0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Code in Xcode
    By rmcinnes in forum C Programming
    Replies: 2
    Last Post: 04-11-2011, 07:27 AM
  2. Replies: 6
    Last Post: 03-09-2011, 06:38 AM
  3. Passing Array To Function & Display Array Contents
    By mcertini in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2010, 01:32 PM
  4. code on passing array from MFC ActiveX to Jscript...
    By 冯锦华 in forum Windows Programming
    Replies: 1
    Last Post: 09-24-2007, 04:05 AM
  5. Passing an Array to a function
    By mmx4000 in forum C Programming
    Replies: 2
    Last Post: 06-19-2007, 01:29 PM