I'm working for the first time with generic types in C and I'm having some problems with my code. My compiler works but when I run my program it prints strange characters.
I have a library with functions that works on generic types of array (insertion and quick sort) and I want to test my library.
I summed up my code with this little example so you don't have to read my whole code. The char_function is the generic function that I want to test in this case and in my main I've the test. I expect this output:
b
c
c
The code:
#include <stdio.h>
#include <stdlib.h>
void generic_function(void** array);
int main(){
char* ch= (char*)malloc(sizeof(char)*3);
ch[0] = 'a';
ch[1] = 'b';
ch[2] = 'c';
generic_function((void**)ch);
printf("%c\n", ch[0]);
printf("%c\n", ch[1]);
printf("%c\n", ch[2]);
return 0;
}
void generic_function(void** array){
array[0] = array[1];
array[1] = array[2];
}