M
Michael
Hi,
I am trying to get an idea of how function pointers work.
I have the following:
#include <stdio.h>
void do_stuff(int*,int,void*);
void getInt(int*);
void showInt(int*);
int main(){
int num_array[10];
do_stuff(num_array, 10, getInt);
do_stuff(num_array, 10, showInt);
return(0);
}
void do_stuff(int *a, int size, void (*process)(int *)){
int i;
for(i = 0; i < size; i++){
process(&a);
}
}
void getInt(int *ptr){
if((scanf("%d", ptr)) != 1){
printf("error");
}
}
void showInt(int *ptr){
printf("%d", *ptr);
}
but I get errors "conficting types for do_stuff" and also warnings "ISO C
forbids passing of arg3 of do_stuff between pointer and void *"
I'm getting nowhere fast here. Can someone help me out with what I have
wrong?
Thanks
Michael
I am trying to get an idea of how function pointers work.
I have the following:
#include <stdio.h>
void do_stuff(int*,int,void*);
void getInt(int*);
void showInt(int*);
int main(){
int num_array[10];
do_stuff(num_array, 10, getInt);
do_stuff(num_array, 10, showInt);
return(0);
}
void do_stuff(int *a, int size, void (*process)(int *)){
int i;
for(i = 0; i < size; i++){
process(&a);
}
}
void getInt(int *ptr){
if((scanf("%d", ptr)) != 1){
printf("error");
}
}
void showInt(int *ptr){
printf("%d", *ptr);
}
but I get errors "conficting types for do_stuff" and also warnings "ISO C
forbids passing of arg3 of do_stuff between pointer and void *"
I'm getting nowhere fast here. Can someone help me out with what I have
wrong?
Thanks
Michael