Thread: invalid conversion from 'int*' to 'int' [-fpermissive]

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    180

    invalid conversion from 'int*' to 'int' [-fpermissive]

    What's wrong with the function call? When i do lSearch(V, size, key) iam just passing key by value, and lSearch has an int to receive not a pointer, why is it whining?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    typedef struct
    {
        int num;
         char name[80];
        float mark;
    }Student;
    
    
    
    
    
    
    int lSearh(Student *V, int size, int key)
    {
        int i=0;
        while((i<size) && (V[i].num<key))
        {
            i++;
        }
        if((i<size) && (V[i].num==key))
        {
            return i;    
        }    
        else
        {
            return -1;
        }
    }
    
    
    
    
    
    
    Student *RemoveStudent(Student *V, int *size, int key)
    {
        int i, j;
        i = lSearch(V, size, key); //Error here with key
        for(j=i;j<*size;j++)
        {
            V[j]=V[j+1];
        }
        *size=*size-1;
        V = (Student *)realloc(V, (*size)*sizeof(Student));
        if(V == NULL)
            return NULL;
        return V;
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    It's "whining" about other things, as well:

    main.c|43|warning: implicit declaration of function 'lSearch'
    That's because there's a typo in the function definition:

    Code:
    int lSearh(Student *V, int size, int key)
    What's wrong with the function call? When i do lSearch(V, size, key) iam just passing key by value, and lSearch has an int to receive not a pointer, why is it whining?
    "key" appears to be fine - the problem seems to be coming from "size".

    Line 40: The "RemoveStudent()" function receives an int pointer called "size".
    Line 43: You pass this int pointer (2nd argument) to the "lsearch()" function.

    But the 2nd argument of "lsearch()" expects an int, not an int pointer as you're passing.

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    180
    Oh yes, how come i not spot that...
    I guess i was too focused on key since the compiler was telling me the error was coming from that location. Will be more careful next time.
    It will be fine passing lSearch(V, *size, key) right? At least it compiles, fwiw

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-31-2013, 07:59 PM
  2. invalid conversion What's this?
    By kyel_dai92 in forum C Programming
    Replies: 6
    Last Post: 04-06-2011, 08:44 AM
  3. error: invalid conversion from 'int' to 'int*'
    By csharp100 in forum C++ Programming
    Replies: 4
    Last Post: 02-22-2011, 07:56 AM
  4. Invalid Conversion
    By cweb255 in forum Windows Programming
    Replies: 2
    Last Post: 05-28-2005, 07:04 AM
  5. invalid conversion
    By black_sol in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2004, 05:42 PM