Interview Questions and Answers

Which of the following function sets first n characters of a string to a given character?

A   strinit()

B   strnset()

C   strset()

D   strcset()


Correct Option - B

Explaination

char *strnset(char *s, int ch, size_t n); Sets the first n characters of s toch

#include 
#include 
int main(void)
{   
char *string = "abcdefghijklmnopqrstuvwxyz";   
char letter = 'x';   
printf("string before strnset: %s\n", string);   
strnset(string, letter, 13);   
printf("string after  strnset: %s\n", string);   
return 0;
}

Report this question

Write Your Comments
!You need to be logged in to post comment

Share This Page -