I'm trying to get the code working, and I don't know where's a mistake. I've tried with references etc but it does not work.
void output(int t[],int n) {
for(int i=0;i<n;i++)
printf("%d ",t[i]);
}
void swap(int *xp, int *yp) {
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void func(int t[], int n) {
output(t,n);
}
void gen_data(int n) {
FILE *data=fopen("dane.txt","w");
srand(time(NULL));
for(int i=0;i<n;i++)
fprintf(data,"%d ",rand()%200-100);
fclose(data);
}
void gen_tab(int *tab, int n) {
FILE *data=fopen("dane.txt","r");
for(int i=0;i<n;i++)
fscanf(data,"%d",&tab[i]);
fclose(data);
}
void start(int tab[],int n,void (*f)(int,int)) {
double a,b;
a=(unsigned)time(NULL);
output(tab,n); //OK
f(tab,n);// CRASH
b=(unsigned)time(NULL);
double result=(b-a)/60;
printf("result: %lf",result);
}
int main() {
int flag;
scanf("%d",&flag);
gen_data(flag);
int *t;
t=(int*)malloc(flag*sizeof(int));
gen_tab(t,flag);
//output(t,flag);
start(t,flag,func);
free(t);
return 0;
}
How can I fix this?
void (*f)(int,int)
this is not the correct type for the function you are passing. – Eugene Sh. May 10 '19 at 16:54