memset()

memset()

Description

Copies the value to the first n characters of the string pointed to, by the argument str[].

Syntax
memset(str[], value, n);

Parameters

Variable

Input

Variable

Input

str[]

This is a pointer to the block of memory to fill

value

This is the value to be set.

The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.

n

This is the number of bytes to be set to the value.

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

Operation success.

SCRIPT_OPERATION_FAILED

Operation failed.

Function call example

Example of placing character to string
new array[25]; main(){ while(1){ memset(array,'p',24); // place 24 'p' characters into array Delay(1000); } }

Notes and Warnings

  • use array[n] to place character into array with offset of n

  • number of characters to be placed cannot be bigger than array size

  • In case offset is needed, keep in mind that while using offset - you still cannot overflow buffer. Meaning that if we start to write from array element no.3  while array size is 10 elements we should not set size variable higher than 8. Otherwise critical error might happen. Here's an example on how it should be done if offset is needed:

copy string with offset example
new array[25]; new offset = 2; main(){ memset(array[offset],'p', (sizeof array)-offset); // place 23 'p' characters into array starting from third element while(1){ Delay(1000); } }