Like Tree1Likes
  • 1 Post By nonoob

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

This is a discussion on Passing an array to a function, failed with exit code 1 (Xcode) within the C Programming forums, part of the General Programming Boards category; Hello people, I'm writing a program (on Xcode, OSX) to find the largest number in an array by passing it ...

  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
    msh
    msh is offline
    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,831
    main should return a 0.
    Salem likes this.

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, 05:38 AM
  3. Passing Array To Function & Display Array Contents
    By mcertini in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2010, 12: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21