please fix my generic function
-
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> -
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>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.
-
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> -
Either a) supply a prototype for Lsearch() before it is called or b) put the definition of Lsearch() before the definition of main()
Thank you so much, it worked very well ^_^ , excuse my ignorance still new in this .
-
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.
Thank you so much, it worked very well ^_^ , excuse my ignorance still new in this .