What about \r ? Why it is not reading? Can any one explain this please?
Nishanth Shetty K said:
(Mon, Feb 14, 2011 01:57:18 AM)
Because it is a carraige return. It does not store in str.
Sairamteja said:
(Mon, Feb 14, 2011 06:04:30 AM)
The question is good and \r is a carriage return.
Nayna said:
(Wed, Mar 2, 2011 03:57:29 PM)
Can anyone explain me...
Why \r doesn't get read..
and if your ans is that because it is a carraige return.
then why \n gets read..it is also a new line type.
Sundar said:
(Thu, Mar 3, 2011 12:03:28 AM)
@Nayna
Let us know the difference between the \r and \n.
\r - is moves the cursor to the left-most position of the CURRENT line.
\n - is moves the cursor to the left-most position of the NEXT line.
Example:
1. printf("India\rBIX");
Output: BIXia
2. printf("India\nBIX");
Output:
India
BIX
Note: It may not work as I said in 32-bit platform. But works fine in Turbo C (under DOS 16-bit platform).
Hope the understand the difference. Have a nice day!
Vineet said:
(Fri, Apr 22, 2011 05:39:44 AM)
Can anyone explain me...
Why \r doesn't get read..
and if your ans is that because it is a carraige return.
then why \n gets read..it is also a new line type.
and plz give me explanation that why \n is printed???????
Riya said:
(Mon, Apr 25, 2011 04:54:00 AM)
@Sundar : Thanks for the perfect explanation.
Sushil said:
(Wed, May 25, 2011 07:08:24 AM)
Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
A newline character makes fgets() stop reading, but it is considered a valid character and therefore it is included in the string copied to str.
A null character is automatically appended in str after the characters read to signal the end of the C string.
Varsha said:
(Tue, Aug 9, 2011 09:44:13 PM)
@Sundar
Thank you.
Nisha said:
(Mon, Aug 22, 2011 03:20:58 PM)
Everyone wrote whatever is already known, but the question is still unanswered. Why the hell \r didn't get stored while \n does!
Anyone. Give the to 'to the point answer' plz!
Nischal said:
(Fri, Sep 2, 2011 09:29:13 AM)
@Sundar
I didn't get your example.
\r is to move cursor to left most position in the current line
printf("india\rbix");
Here output must be, first it prints india then \r so again cursor is moved to left most position right?
Please help me this doubt.
Nikita said:
(Tue, Sep 20, 2011 09:03:25 PM)
Why in ans there is '\0'.
Jyoti said:
(Fri, Oct 7, 2011 10:07:47 PM)
Nikita, because In C string always ended with null (\0) character.
Kamal Dua said:
(Sun, Oct 9, 2011 11:00:24 AM)
This question is on I/O.
In C when we attempt to write a string(which is done using function fputs()).
It converts "\n" into "\r\n".
But while reading using function(which is done using function fgets()). "\r\n" is converted to "\n".
Actually this is a feature of standard library functions.
Hope you guys understand. Have a nice day!
Vivek said:
(Fri, Dec 2, 2011 02:24:31 AM)
Please any one clear exlpain.
I don't understand.
Nutan said:
(Mon, Jan 9, 2012 12:05:34 AM)
@kamal dua
Thanks for explain it.....
Surendra said:
(Fri, Jan 27, 2012 07:39:13 PM)
@kamal Dua
You are right dude.... That's why it printed \n instead of "\r\n".
Thnx.........