Function name : strset
Header file : <string.h>
Function prototype : char *strset(char *str, char c);
Function : Set all characters in a string to specified characters
Parameters : char *str is the target string to be set
char c is the specified character to be set to
Return value : Returns a pointer to the replaced string, essentially returning str
Note: This function directly changes the value of str and then returns str, so the str here must be a string array and cannot be a string pointer.
Program example: Set all characters in the string array string to character c
#include<stdio.h>#include<string.h>intmain(void){charstring[20]=www.dotcpp.com;charsymbol='c';printf(Beforestrset():%sn,string); strset(string,symbol);printf(Afterstrset():%sn,string);return0;}
Running results:
Beforestrset():www.dotcpp.comAfterstrset():cccccccccccccc