C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - General Questions (Q.No. 1)
1.
In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?
Answer: Option
Explanation:
Declaration: char *fgets(char *s, int n, FILE *stream);
fgets reads characters from stream into the string s. It stops when it reads either n - 1 characters or a newline character, whichever comes first.
Therefore, the string str contain "I am a boy\n\0"
Discussion:
57 comments Page 5 of 6.
Satish said:
10 years ago
Hi,
If \r is in printf () then the the characters after it are printed first, now let the number of characters printed till now is N then the first n characters are skipped and following characters are printed upto \r.
If \r is in printf () then the the characters after it are printed first, now let the number of characters printed till now is N then the first n characters are skipped and following characters are printed upto \r.
Saraswathi sivaguru said:
10 years ago
How the \o and \n characters are printed? Please explain?
Madhav said:
10 years ago
If we are writing.
printf ("hello\n welcome");
Output will be:
Hello.
Welcome.
But when we a are writing.
Printf ("hello\n");
Why? Hello\n is printed.
I mean this time \no is also printed.
Why? Please explain.
printf ("hello\n welcome");
Output will be:
Hello.
Welcome.
But when we a are writing.
Printf ("hello\n");
Why? Hello\n is printed.
I mean this time \no is also printed.
Why? Please explain.
Aiza said:
10 years ago
Can anybody explain to me why its not be "I am a boy\r\0"?
Gaurav said:
9 years ago
"I am a boy\n\0"
"\n\0" why the two came in the picture and where is gone \r.
please, don't tell me above things again. Explain me in a different way.
"\n\0" why the two came in the picture and where is gone \r.
please, don't tell me above things again. Explain me in a different way.
(1)
Ganga said:
9 years ago
Why we can write \r. What is the use of that?
Please explain.
Please explain.
APARNA said:
8 years ago
Will anyone explain it with an example?
Abhi said:
8 years ago
For me, only I am a boy is getting in a string.
Suman said:
8 years ago
@Sundar. Please, explain again.
printf("india\rBIX") should print india since you said the control shifts to a leftmost position that is i?
printf("india\rBIX") should print india since you said the control shifts to a leftmost position that is i?
(1)
Tanya said:
8 years ago
Yes @Suman.
But that overwrites 'ind' and changes it to 'bix' and hence the output.
But that overwrites 'ind' and changes it to 'bix' and hence the output.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers