**Hey guys i'm having trouble casting my void pointer array to point to my float array, i want my void pointer to point to the array of floats so void[0]=float[0] i know that a void ptr and float are not the same size so i cannot assign it in this manner void[0]=float[0] how do i tackle this issue? Thanks!
void *ptr[5];
float arr[5];
for(i=0;i<5;i++)
ptr[i]=arr[i];
How do i fix this issue? i want to send any array using a void pointer array I have added the code:
#define _CRT_SECURE_NO_WARNINGS
#define N 5
#include <stdio.h>
#include <stdlib.h>
typedef enum {FALSE,TRUE} BOOL;
BOOL Int_Sum(void* a, void* b, void* c)
{
if (*(int*)a + *(int*)b == *(int*)c)
return TRUE;
return FALSE;
};
BOOL Float_sum(void*a, void* b, void* c)
{
if (*(float*)a + *(float*)b == *(float*)c)
return TRUE;
return FALSE;
};
BOOL Sum(BOOL(*F)(void*, void*, void*), void** p_num, void* number)
{
int i = 0,j=0;
for (i = 0; i <N; i++)
{
for (j = 0 ; j <N; j++)
{
if (j != i)
{
if (F(&p_num[i], &p_num[j], number))
return TRUE;
}
}
}
return FALSE;
}
int main()
{
int num[] = { 3,5,23,5,6 }, i=0, value;
float fnum[] = { 3.5,5.0,2.3,5.8,6.2 }, fvalue;
void* p_num[N];
float* f_pnt[N];
BOOL* fpnt;
fpnt=Int_Sum;
for (i = 0; i < N; i++)
p_num[i] = num[i];
printf("\nPlease enter an integer number:");
scanf("%d", &value);
if (Sum(fpnt, p_num,&value )== TRUE)
printf("There is such sum\n");
else
printf("There is no such sum\n");
printf("\nPlease enter an integer number:");
scanf("%f", &fvalue);
fpnt = Float_sum;
for (i = 0; i < N; i++)
{
(float*)p_num[i] =fnum+i;
}
if (Sum(fpnt, p_num, &fvalue))
printf("There is such sum\n");
else printf("There is no such sum\n");
return 0;
}
Having trouble with the funciton when i want to use the float array
**