Thread: improper pointer/ integer combination?

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

    improper pointer/ integer combination?

    I seem to get a line 19: warning: improper pointer/integer combination: arg #1, when I run this. I don't know 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;
      int list;
    
      for (i = 0; i < ARRAY; i++)
      {
        j = getRandA(1, 1000);
        selectionSort(j, 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
    Registered User
    Join Date
    Dec 2003
    Posts
    12
    Try changing this
    Code:
    void selectionSort(int list[], int last);
    to
    Code:
    void selectionSort(int list, int last);
    Or change the actual paramater, whichever it was you were meaning to do.

    I'm assuming its the actual parameter you want to change. Obviously then you need to declare j as a pointer.
    Last edited by kalium; 11-15-2005 at 11:37 PM.

  3. #3
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    There are other warnings also....u also need to include time.h...but are u sure what u r doing

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You don't need return; at the end of every void function. And you also need <time.h> (as mentioned) because of your use of time().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Don't cross-post: http://cboard.cprogramming.com/showthread.php?t=72281.

    What everyone's saying is that selectionSort() takes a pointer (or array), and you're giving it an int:
    Code:
    void selectionSort(int list[], int last);
    
    int main(void)
    {
      int i;
      int j;
      int first = 1;
      int last = 500;
      int list;
    
      for (i = 0; i < ARRAY; i++)
      {
        j = getRandA(1, 1000);
        selectionSort(j, last);
      }
    So, either make selectionSort take an int argument, or pass it an array (or pointer).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  3. Problem with "pointer from integer without a cast"
    By firyace in forum C Programming
    Replies: 6
    Last Post: 05-11-2007, 09:48 AM
  4. comparison between pointer and integer
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-07-2006, 01:15 PM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM