Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i cast the void pointer to char array in a multithreaded program in C [closed]

Tags:

c

how do i cast the void pointer to char array in a multithreaded program in C

void* write(void* ptr) {    
   char array[100];
   array= (char*)ptr;
   printf("%s",array);  
}
like image 627
Omar Hashmi Avatar asked Dec 06 '25 08:12

Omar Hashmi


2 Answers

You can't.

You can cast it to a char pointer, however:

void* write(void* ptr){    
   char *array;
   array= (char*)ptr;
   printf("%s",array);  
}
like image 139
Paul Roub Avatar answered Dec 08 '25 22:12

Paul Roub


You might need to use a pointer to a char array and not a fixed-size array.

void *ptr;
...
char *message;
message = (char *) ptr;

Source

like image 41
xikkub Avatar answered Dec 08 '25 20:12

xikkub