strset() function in C Programming Language : Set Characters in String to Specific Value in C
☰Fullscreen
Table of Content:
strset() function sets all the characters in a string to given character. Syntax for strset( ) function is given below.
Syntax
char *strset(char *string, int c);
Important Note
strset()
function is non standard function which may not available in standard library in C.
Program
In this program, all characters of the string "atnyla" is set to $ using strset( ) function and output is displayed as $$$$$$.
#include #include int main() { char str[20] = "atnyla"; printf("Original string is : %s \n", str); printf("Test string after strset() : %s \n",strset(str,'$')); printf("After string set: %s \n",str); return 0; }
Output
Original string is : atnyla Test string after strset() : $$$$$$ After string set: $$$$$$ Press any key to continue . . .