Thread: Trouble passing information from one function to another function

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    33

    Trouble passing information from one function to another function

    I'm trying to pass values from the main() function to the selectionSort() function, but it keeps saying the following:

    hw2n1.c: In function `main':
    hw2n1.c:25: warning: passing arg 1 of `selectionSort' makes pointer from integer without a cast
    hw2n1.c:25: error: void value not ignored as it ought to be


    The following is my code:

    Code:
    #include <stdio.h>
    #define NUM_INT 1000
    void selectionSort(int a[], int size);
    
    int main (void)
    {
      int input[NUM_INT] = {0};
      int i;
      int sorted;
    
      printf("please input arrays of ints to be sorted ");
      for (i = 0; i < NUM_INT; i++)
      {
        scanf("&#37;d", &input[i]);
        printf("%d ", input[i]);  //TESTING
    
        if (input[i] < -2)
        {
          printf("program error (one of the numbers is less than -2)\n ");
          return 0;
        }
        if(input[i] == -1)
        {
           printf("restart sort and new line");
           sorted = selectionSort(input[i], NUM_INT);   //TROUBLE SPOT, DON'T KNOW WHAT TO DO!
        }
        if (input[i] == -2)
        {
          printf("Inputed Arrays are: %d", input[i]);
        }
    
      }
    
     // printf("Inputed Arrays are: %d", input[i]);
      printf("sorted is: %d", sorted);
    
      return 0;
    }
    
    //SELECTION SORT ALGORITH
    void selectionSort(int a[], int size)
    {
      int i, j, min;
    
      for (i = 0; i < size - 1; i++)
      {
        min = i;
        for (j = i+1; j < size; j++)
        {
           if (a[j] < a[min])
              min = j;
        }
        swap(a[i], a[min]);
      }
    }

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    umm....you may want to send your function the whole array instead of a single element in that array.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Passing a byte and its bits to a function
    By rtarbell in forum C Programming
    Replies: 9
    Last Post: 12-04-2008, 09:24 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM