What is memset, and why it is used, When it is used?

I need a simple example progam for this with clear definition

Showing Answers 1 - 9 of 9 Answers

Bharani

  • Aug 31st, 2007
 

Memset is used to set a buffer with a specific character
 for example
memset (dptr, 'A', 10); // sets the first 10 character to character 'A'

#include <memory.h>
#include <stdio.h>

int main( void )
{
   char buffer[] = "This is a test of the memset function";

   printf( "Before: %sn", buffer );
   memset( buffer, '*', 4 );
   printf( "After:  %sn", buffer );
}

Output
Before: This is a test of the memset function
After:  **** is a test of the memset function

  Was this answer useful?  Yes

How will this memset() function willl handle the worst case (ie) when the string is lesser than the given length
If my string is  
 
char string[]="i love my india";
If I use the function memset(string, '*' , 20);

Will it handle these type of complexities?

  Was this answer useful?  Yes

Vinay

  • Jan 22nd, 2013
 

This code gives warnings which is not the good sign while dealing with the network programming.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions