Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. please fix my generic function

please fix my generic function

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11471444
    wrote on last edited by
    #1

    This program doesn't compile and gives me error "Conficting types of L search" . I ran out of all trials and I am so confused why the heck it gives me this error . I would appreciate your contributions to solve my problem . the function does front back search of an array, if any number matches it sends back its address.

    #include <stdio.h>

    int main(void) {
    int arr []= {1,2,3,4,5,6,7,8,9,10} ;
    int req = 5;

    Lsearch(arr,&req,10,4); // (sizeof(arr)/sizeof(int)),sizeof(req)
    
    
    return 0;
    

    }

    void *Lsearch(void *base,void *key,int n,int elemsize)
    {
    for(int i = 0 ; i<n;i++)
    {
    void *elemAddr = (char*)base + i*elemsize ;
    if(memcmp(key,base,elemsize)==0) return elemAddr ;
    }
    return NULL ;
    }</pre>

    Richard Andrew x64R K 2 Replies Last reply
    0
    • U User 11471444

      This program doesn't compile and gives me error "Conficting types of L search" . I ran out of all trials and I am so confused why the heck it gives me this error . I would appreciate your contributions to solve my problem . the function does front back search of an array, if any number matches it sends back its address.

      #include <stdio.h>

      int main(void) {
      int arr []= {1,2,3,4,5,6,7,8,9,10} ;
      int req = 5;

      Lsearch(arr,&req,10,4); // (sizeof(arr)/sizeof(int)),sizeof(req)
      
      
      return 0;
      

      }

      void *Lsearch(void *base,void *key,int n,int elemsize)
      {
      for(int i = 0 ; i<n;i++)
      {
      void *elemAddr = (char*)base + i*elemsize ;
      if(memcmp(key,base,elemsize)==0) return elemAddr ;
      }
      return NULL ;
      }</pre>

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      You failed to include a function prototype at the top of the program thus:

      void* Lsearch(void*, void*, int, int);

      int main(void) {

      // Rest of program here

      The difficult we do right away... ...the impossible takes slightly longer.

      U 1 Reply Last reply
      0
      • U User 11471444

        This program doesn't compile and gives me error "Conficting types of L search" . I ran out of all trials and I am so confused why the heck it gives me this error . I would appreciate your contributions to solve my problem . the function does front back search of an array, if any number matches it sends back its address.

        #include <stdio.h>

        int main(void) {
        int arr []= {1,2,3,4,5,6,7,8,9,10} ;
        int req = 5;

        Lsearch(arr,&req,10,4); // (sizeof(arr)/sizeof(int)),sizeof(req)
        
        
        return 0;
        

        }

        void *Lsearch(void *base,void *key,int n,int elemsize)
        {
        for(int i = 0 ; i<n;i++)
        {
        void *elemAddr = (char*)base + i*elemsize ;
        if(memcmp(key,base,elemsize)==0) return elemAddr ;
        }
        return NULL ;
        }</pre>

        K Offline
        K Offline
        k5054
        wrote on last edited by
        #3

        Either a) supply a prototype for Lsearch() before it is called or b) put the definition of Lsearch() before the definition of main()

        U 1 Reply Last reply
        0
        • K k5054

          Either a) supply a prototype for Lsearch() before it is called or b) put the definition of Lsearch() before the definition of main()

          U Offline
          U Offline
          User 11471444
          wrote on last edited by
          #4

          Thank you so much, it worked very well ^_^ , excuse my ignorance still new in this .

          1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            You failed to include a function prototype at the top of the program thus:

            void* Lsearch(void*, void*, int, int);

            int main(void) {

            // Rest of program here

            The difficult we do right away... ...the impossible takes slightly longer.

            U Offline
            U Offline
            User 11471444
            wrote on last edited by
            #5

            Thank you so much, it worked very well ^_^ , excuse my ignorance still new in this .

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups