Newbie: ... makes pointer from integer without a cast

This is a discussion on Newbie: ... makes pointer from integer without a cast within the C Programming forums, part of the General Programming Boards category; Hello, i know this error message was asked many times but if you're a newbie you can't even understand what's ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    10

    Newbie: ... makes pointer from integer without a cast

    Hello, i know this error message was asked many times but if you're a newbie you can't even understand what's going on . This code gives that error, any help would be appreciated, thanks...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    #include <conio.h>
    #define SIZE 64
    void fill_array(int[]);
    void display_array(int[]);
    int binary_search(int[],int);
    void bubblesort(int[]);
    int main()
    {
     int array1[SIZE], number, i;
     srand(time(NULL));
     fill_array(array1);
     bubblesort(array1);
     display_array(array1);
     printf("Enter what you are looking for: ");
     scanf("%d",&number);
     i = binary_search(array1, number);
     if(i>=0)
      printf("The element you are looking for is %d and its in %d. location",array1[i],i); 
     else
      printf("The element you are looking for is not in array");
     getch();
     
     system("Pause");
     return 0;
    }
    void fill_array(int my_array[])
    {
     int j=0;
     for(j=0;j<SIZE;j++)
     {
      my_array[j]=rand()%100;
     }
    }
    void display_array(int my_array[])
    {
     int k = 0;
     for(k=0;k<SIZE;k++)
     {
      printf("%5d",my_array[k]);
      if(((k+1)%8)==0)
       printf("\n");
     }
    }
    void bubblesort(int my_array[])
    {
     int i, j, temp;
     for(i=1;i<=(SIZE-1);i++)
     {
      for(j=0;j<=(SIZE-2);j++)
      {
       if(my_array[j]>my_array[j+1])
       {
        temp=my_array[j];
        my_array[j]=my_array[j+1];
        my_array[j+1]=temp;
       }
      }
     }
    }
    int binary_search(int my_array[],int num)
    {
     int middle, high, low, flag = -1;
     high = SIZE-1;
     low = 0;
     while(high >= low)
     {
      middle =(int)((high+low)/2);
      low = middle+1;
      if(num<my_array[middle])
       high=middle-1;
      if(num==my_array[middle])
      {
       return(middle);
      }
     }
     return (flag);
    }
    Last edited by ejjjjj; 05-12-2010 at 09:24 AM. Reason: Solved

  2. #2
    Registered User GL.Sam's Avatar
    Join Date
    Aug 2009
    Posts
    88
    >int binary_search(int[],int[]);
    This.
    The only good is knowledge and the only evil is ignorance.
    ~Socrates

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    10
    thank you GL.Sam

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    10
    The programme is working and displaying the numbers but when you enter a number which is in the displayed list, "The element you are looking for is not in array" is returning, but not for all the numbers, just the numbers which are above the last line and that means just the last 8 numbers are returning a true value. Isn't this code supposed to give the number's array no. if they are in the displayed list? or am i wrong? Thanks...

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can't automatically set low = middle+1 -- if your data is in the low half of the set, then you've just eliminated it.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    10
    @tabstop so what's your suggestion? i'm newbie

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I'm pretty sure my suggestion was "don't automatically set low = middle + 1". You can only adjust the low/high limits after you know which half your data is in.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-24-2010, 05:41 PM
  2. Replies: 4
    Last Post: 01-27-2009, 02:33 PM
  3. "assignment makes integer from pointer without a cast"
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-04-2002, 04:26 AM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 11:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM

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