strset() function in C Programming Language : Set Characters in String to Specific Value in C

Rumman Ansari   Software Engineer   2024-07-05 04:33:55   7480  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰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<stdio.h>
#include<string.h>
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 . . .