this program just starts and terminates

This is a discussion on this program just starts and terminates within the C Programming forums, part of the General Programming Boards category; ok so im fairly new to C, but im hoping to progress quickly im trying to do an exercise or ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    3

    this program just starts and terminates

    ok so im fairly new to C, but im hoping to progress quickly
    im trying to do an exercise or rather change it from a tutorial
    iv spent some time but can't figure out why this isnt running

    it doesnt ask me for input althought it shud do

    Code:
    #include <stdio.h>
    
    int a[5];
    int bubblesort(); /* function prototype for bubble sort */
    int takeinput();
    int main()
    {
    	int takeinput();
    	int bubblesort();
    }
    
    
    int takeinput()
    {
    	int input;
    	int i;
    	int b;
    
    	i = 0;
    	b = 5;
    	for (i=0; i < b; i++)
    		{
    		scanf("%d",&input);
    			a[i] = input;;
    
    	}
    
    		return 0;
    
    }
    
    
    int bubblesort()
    
    {
    
    /* bubble sort the array */
    
    int x,y,t,i;
    int n = 5;
    for (x=0; x < n-1; x++)
        for (y=0; y < n-x-1; y++)
            if (a[y] > a[y+1])
            {
                t=a[y];
                a[y]= a[y+1];
                a[y+1]=t;
            }
    /* print sorted array */
    printf("--------------------\n");
    for (i=0; i < n; i++)
    printf("%d\n",a[i]);
    
    return 0;
    
    }
    i will appreciate it if someone can point me in the right direction ..

    as to where im going wrong , there are no compile errors ..

  2. #2
    Watch for flying houses. Nessarose's Avatar
    Join Date
    Sep 2004
    Posts
    46
    In main() you're re-declaring the functions. Change it to:

    Code:
    int main()
    {
        takeinput();
        bubblesort();
    }
    Cheers.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    3
    omg thanks man, i just cudnt see it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help
    By hellBOY in forum C Programming
    Replies: 4
    Last Post: 01-13-2009, 10:59 AM
  2. arrays and piping and frustration
    By ihatec++ in forum C++ Programming
    Replies: 13
    Last Post: 05-28-2008, 06:31 AM

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