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?
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 3 of 3.
Sree harsha said:
8 years ago
Can anyone tell why illegal action is committing in dev compiler? Please help me.
Abhishek Singh said:
8 years ago
@ALL.
#include<bits/stdc++.h>
using namespace std;
main(){
char s[]="abhishek";
char p[]="abhiaana";
strnset(s,'l',3);
memset(p,'o',2);
cout<<s<<' '<<p;
}
#include<bits/stdc++.h>
using namespace std;
main(){
char s[]="abhishek";
char p[]="abhiaana";
strnset(s,'l',3);
memset(p,'o',2);
cout<<s<<' '<<p;
}
Rathna suresh said:
7 years ago
What is the meaning of *char?
(3)
S.SAHA said:
4 years ago
This function return values that are as follows;
if Return value < 0 then it indicates str1 is less than str2.
if Return value > 0 then it indicates str2 is less than str1.
if Return value = 0 then it indicates str1 is equal to str2.
if Return value < 0 then it indicates str1 is less than str2.
if Return value > 0 then it indicates str2 is less than str1.
if Return value = 0 then it indicates str1 is equal to str2.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers