User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:memset

memset

    #include <stdlib.h>
    void *memset(void *str, int c, size_t n); 

memset Fill / overwrite memory region with certain characters
str = Target memory block /c string
c = value byte that is used to overwrite
n = number of chars to be copied

memset C Sourcecode Example

/* 
 * memset example code
 * http://code-reference.com/c/string.h/memset
 */
#include <stdio.h>
#include <string.h>
 
int main(void) {
   char string[15] = "memset example";
   int i;   
 
for (i=0;i<=15;i++) {
      memset(string ,'*', i);
      printf("%s\n",string);
   }
return 0;
}

output of memset sourcecode example

  user@host:~/code-reference.com# ./memset 
  memset example
  *emset example
  **mset example
  ***set example
  ****et example
  *****t example
  ****** example
  *******example
  ********xample
  *********ample
  **********mple
  ***********ple
  ************le
  *************e
  **************
  ***************

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/memset.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz