Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Function memset in C programming

September 18, 2013 Posted by: GPA Views: 26747 0 comments

Problem

Function memset in C programming.

Solution

In this section, we tell how you can use function memset()  of header file <string.h>.

Declaration:

void *memset( void *str, int c, size_t n );

Function memset copies (n) characters of value (c) into the first n characters of the value str.
In this example we use function memset to copy 'k' into the first 10 characters of str.

Example:



#include <stdio.h>
#include <stdlib.h>
#include <string.h>//for function memset
//main function
int main(int argc, char *argv[])
{
char str[]="Simple test string";
printf("globalproganswer.com\n");
printf("str is: %s\n",str);
//call function memset
printf("str after memset(str, 'k',10) is: %s\n",memset(str, 'k',10));
printf("\n\n");//new line
system("PAUSE");//delay
return 0;
}

Output

Function memset

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe