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 2 of 6.
Ganga said:
9 years ago
Why we can write \r. What is the use of that?
Please explain.
Please explain.
Chetan said:
1 decade ago
"\r" will be stored in buffer.
If you try to print str (buffer) with printf or in a file you will not able to see the difference because both are white space. Try to print buffer with debugger like GDB or you can print character one by one.
If you try to print str (buffer) with printf or in a file you will not able to see the difference because both are white space. Try to print buffer with debugger like GDB or you can print character one by one.
Kalyani said:
1 decade ago
@Richard.
\0 is a default null character that will be stored automatically at the end of the file when we use file related functions in C.
\0 is a default null character that will be stored automatically at the end of the file when we use file related functions in C.
Ganesh sable said:
1 decade ago
In this program,
\r same like \0.
So output print to \r .
And cursor automatically go new line,
That wise \n is must print in c this is rule in C "I am a boy\n\0" is output.
\r same like \0.
So output print to \r .
And cursor automatically go new line,
That wise \n is must print in c this is rule in C "I am a boy\n\0" is output.
Raviranjan kumar said:
1 decade ago
Many many so thanks guys to discussing this topic.
Neelu said:
1 decade ago
In this program only main() is sufficient or necessary int main().
Anis gupta said:
1 decade ago
Hi dear.
I think the answer will be D, because newline return require.
For Linux \n.
For windows \r\n.
For mac os \r.
I think the answer will be D, because newline return require.
For Linux \n.
For windows \r\n.
For mac os \r.
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.
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.
Saraswathi sivaguru said:
10 years ago
How the \o and \n characters are printed? Please explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers