Computer Science, asked by sanjaykumar547, 6 months ago

write a c program toread the input string and hide the n number of characters with the special symbol using strnset() function​


ankitkumar9931938: hii
sanjaykumar547: hi
ankitkumar9931938: how are you please foll

Answers

Answered by ankitkumar9931938
0

Answer:

strnset() function in C

The strnset() function is a builtin function in C and it sets the first n characters of a string to a given character. If n is greater than the length of string, the length of string is used in place of n.

Syntax:

char *strnset(const char *str, char ch, int n);

Parameters:

str: This is the original string in which some character are replaced by a given character.

ch: ch represents the given character.

n: n represents the number of character which is replaced by the given character.

Return Value: It returns the modified string obtained after replacing the first

n characters of the given string str.

Below programs illustrate the strnset() function in C:

Program 1:

// C program to illustrate

// the strnset() function

#include <stdio.h>

#include <string.h>

int main()

{

char str[] = "GeeksforGeeks";

printf("Original String: %s\n", str);

// First 5 character of string str

// replaced by character '*'

printf("Modified String: %s\n", strnset(str, '*', 5));

return 0;

}

Output:

Original String: GeeksforGeeks

Modified String: *****forGeeks

Program 2:

// C program to illustrate

// the strnset() function

#include <stdio.h>

#include <string.h>

int main()

{

char str[] = "Computer Science";

printf("Original String: %s\n", str);

// First 5 character of string str

// replaced by character '*'

printf("Modified String: %s\n", strnset(str, '*', 5));

return 0;

}

Output:

Original String: Computer Science

Modified String: *****ter Science

Note: The strnset() function is not a part of the standard C library and thus might not run on the online compilers.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

Article Tags : C C-FunctionsC-String

Practice Tags : C


sanjaykumar547: I want output as####set
sanjaykumar547: runtime input is#4
sanjaykumar547: pls help
Answered by Anonymous
1

Program 1:

// C program to illustrate

// the strnset() function

#include <stdio.h>

#include <string.h>

int main()

{

char str[] = "GeeksforGeeks";

printf("Original String: %s\n", str);

// First 5 character of string str

// replaced by character '*'

printf("Modified String: %s\n", strnset(str, '*', 5));

return 0;

}

Output:

Original String: GeeksforGeeks

Modified String: *****forGeeks

Program 2:

// C program to illustrate

// the strnset() function

#include <stdio.h>

#include <string.h>

int main()

{

char str[] = "Computer Science";

printf("Original String: %s\n", str);

// First 5 character of string str

// replaced by character '*'

printf("Modified String: %s\n", strnset(str, '*', 5));

return 0;

}

Output:

Original String: Computer Science

Modified String: *****ter Science

Your program

thanks

hope this helps

take care

may God bless you and your family


Anonymous: huh
sanjaykumar547: pls send me full program as per my output pls
sanjaykumar547: hlo
sanjaykumar547: pls
Anonymous: just change the strings
sanjaykumar547: I didn't know anything just now I'm trying
sanjaykumar547: now test going on pls send me the full program as per my output
Anonymous: buddy the procedure is very long I can't
sanjaykumar547: pls only body of the program..
Anonymous: provided you
Similar questions