Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Functions and Pointers
  5. Built-in functions
  6. Set n Chars

Set n Chars

Use of strnset( ) function

#include<stdio.h>
#include<string.h>
int main() 
{
    char s[10], ch;
    int n;
    puts("Enter string1:");
    gets(s);
    puts("Enter the character:");
    scanf("%c",&ch);
    puts("Enter the number of characters to set:");
    scanf("%d",&n);
    puts("string before setting");
    puts(s);
    strnset(s,ch,n);
    puts("string after setting");
    puts(s);
    return 0;
}

Output

Enter string1:
Hello
Enter the character:
a
Enter the number of characters to set:
3
string before setting
Hello
string after setting
aaalo

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments