C Reference String Operation: memset()

The function memset() copies x into a buffer y and does this n times.

Usage:

void *memset( void *y, int x, size_t n);

Note: memset can be used to set all values of an array to zero (very efficient!)

An example: memset( an_array, ‘\0’, sizeof_array)

memchr() source code example:


	#include<stdio.h>
	#include<string.h>

	main()
	{
		char line[100];
		strcpy(line, "aacc");

		memset(line,'b',2);
		printf("%s\n", line);
	}

Output of the example:


	bbcc

This entry was posted in C Reference string.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.