title: create my own memset function in c
body: <p>here is the prototype:</p>
  
  <pre><code>void *memset(void *s, int c, size_t n)
  </code></pre>
  
  <p>first im not sure if I have to return something because when I use the memset i do for example</p>
  
  <pre><code>memset(str, 'a', 5);
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>str = memset(str, 'a', 5);
  </code></pre>
  
  <p>here is where I am with my code:</p>
  
  <pre><code>void *my_memset(void *b, int c, int len)
  {
      int i;
  
      i = 0;
      while(b &amp;&amp; len &gt; 0)
      {
          b = c;
          b++;
          len--;
      }
      return(b);
  }
  
  int main()
  {
      char *str;
  
      str = strdup("hello");
      my_memset(str, 'a', 5);
      printf("%s\n", str);
  }
  </code></pre>
  
  <p>I dont want to use array in this function, to better understand pointer and memory, so I dont get 2 things:
  - how to copy the int c into a character on my void b pointer
  - what condition to use on my while to be sure it stop before a '\0' char</p>
  
  <p>edit: i was wondering is there a way to do this function without casting ?</p>