C Programming - Strings - Discussion

Discussion Forum : Strings - General Questions (Q.No. 1)
1.
Which of the following function sets first n characters of a string to a given character?
strinit()
strnset()
strset()
strcset()
Answer: Option
Explanation:

Declaration:

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

#include <stdio.h>
#include <string.h>

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;
}

Output:

string before strnset: abcdefghijklmnopqrstuvwxyz

string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz

Discussion:
24 comments Page 2 of 3.

Anandrao Sakhare said:   1 decade ago
#include <stdio.h>
#include <string.h>

main()
{
char str[]="%f%d%c\n\t%d";
int i;
for(i=0;i<10;i++)
printf("%c",str[i]);
}

Output :
%f%d%c
%d

Avnish Patel said:   10 years ago
@Tejaswi you are right,

Executing this program, compiler gives following error.

In function 'main': Undefined reference to 'strnset'

Sanju said:   9 years ago
As far as I know. We can't modify a string literal. Then how its getting modified without giving any error?

Can anyone explain?
(1)

Bhargav said:   1 decade ago
But in strings strnset is not a predefined functions. By compiling the above program it showing some error.

Can you explain?

Sree harsha said:   8 years ago
Can anyone tell why illegal action is committing in dev compiler? Please help me.

Satish rajnale. said:   1 decade ago
How to add two number in C language without using "+" operator ?

Moni said:   9 years ago
What means for the strnset? and where to use strnset?

Usha said:   1 decade ago
What is the difference between strnset and strcset?

Tejaswi said:   1 decade ago
This program gives run time error while executing.
(1)

Prathyusha said:   1 decade ago
Please some one can explain what is "strnset".


Post your comments here:

Your comments will be displayed after verification.