Error.

This is a discussion on Error. within the C Programming forums, part of the General Programming Boards category; The random numbers that are created are supposed to go through the selection sort that was given. For some reson ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    10

    Error.

    The random numbers that are created are supposed to go through the selection sort that was given. For some reson I have an error on line 18 and I am unsure why?

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #define ARRAY 500
    int getRandA(int min, int max);
    void exchangeSmallest(int list[], int first, int last);
    void selectionSort(int list[], int last);
    
    int main(void)
    {
      int i;
      int j;
      int first = 1;
      int last = 500;
    
      for (i = 0; i < ARRAY; i++)
      {
        j = getRandA(1, 1000);
        selectionSort(int list[j], int last);
      }
    
    
      return(0);
    }
    
    int getRandA(int min, int max)
    {
      static int I = 0;
      int rn;
    
      if (I == 0)
      {
        srand(time(NULL));
        I = 1;
      }
    
      rn = (rand() % (max - min +1)+ min);
    
      return(rn);
    }
    
    void selectionSort(int list[], int last)
    {
      int current;
    
      for(current = 0; current < last; current++)
      {
        exchangeSmallest(list, current, last);
      }
      return;
    }
    
    void exchangeSmallest(int list[], int current, int last)
    {
      int walker;
      int smallest;
      int tempData;
    
      smallest = current;
      for(walker = current +1; walker <= last; walker++)
      {
        if (list[walker] < list[smallest])
        {
          smallest = walker;
        }
      }
      tempData = list[current];
      list[current] = list[smallest];
      list[smallest] = tempData;
      return;
    }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Code:
    selectionSort(int list[j], int last);
    Code:
    exchangeSmallest(list, current, last);
    Do you see a difference in the method used for the function arguments in those two function calls?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    10
    I don't see it .

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Code:
    selectionSort(int list[j], int last);
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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