memset Implementation

Hi everyone, I was thinking of implementing memset.... but got stuct ... Here is the code that I wrote ...

#include<stdio.h>
void my_memset(void *ptr,int x,int no_of_bytes){

unsigned char c;

while(no_of_bytes--){
c = (unsigned char) x;

*((char *)ptr ) = c ;

((char *))ptr++;

}

}
int main(){

int *array,i;
array = (int *)malloc(10*sizeof(int));

my_memset(array,0,40);

for(i=0;i<10;i++){
printf("%d ",array[i]);
}
return 0;

}

This wont work when we want to initialize the array by 1. The problem is we are initializing each byte with 1. But other than this how to make this function generic and type cast the void pointer accordingly ?
Topic archived. No new replies allowed.