Function name : strnset
Header file : <string.h>
Function prototype : char *strnset(char *str, char ch, unsigned n);
Function : Set the first few characters of the specified string to the specified characters
Parameters : char *str is the string to be set
char ch is the character to be set
unsinged n is the number of characters set
Return value : Returns a pointer to the set string
Note : This function modifies the value of str, so str can only be a character array, not the string pointed to by the string pointer.
Program example : Replace the first n characters of string string with '!'
#include<string.h>#include<stdio.h>intmain(void){charstring[50]=Ilikewww.dotcpp.com;charletter='!';printf(stringbeforestrnset:%sn,string);strnset( string,letter,6);printf(stringafterstrnset:%sn,string);return0;}
Running results:
stringbeforestrnset:Ilikewww.dotcpp.comstringafterstrnset:!!!!!!www.dotcpp.com