Monday, 15 April 2013

MEMSET Implementation in C
#include <stdio.h>

void *mymemset(void *ptr, int value, size_t num){
    size_t i;
    // Typecast to char so that pointer increment can be done as
    // void pointer can't be increment because compiler 
    // does not know the size of "ptr"
    char *cPtr = ptr;
    for(i = 0; i<num; i++,cPtr++){
        *cPtr = value;
    }
    return ptr;
}

int main(){
    char a[]="Umesh is typing this line for testing mymemset";
    mymemset(a,'0',10);
    printf("%s\n", a);
    return 0;
}

No comments:

Post a Comment