- strnset( ) function sets portion of characters in a string to given character. Syntax for strnset( ) function is given below.
char *strnset(char *string, int c);
- strnset( ) function is non standard function which may not available in standard library in C.
Example program for strnset() function in C:
- In this program, first 4 characters of the string “Test String” is set to “#” using strnset( ) function and output is displayed as “#### String”.
#include<stdio.h> #include<string.h> int main() { char str[20] = "Test String"; printf("Original string is : %s", str); printf("Test string after string n set" \ " : %s", strnset(str,'#',4)); printf("After string n set : %s", str); return 0; }
Output:
Original string is : Test String
Test string after string set : #### String
|
0 comments:
Post a Comment