473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"streams"

I have a question about C's abstract "streams" (that I can't seem to
FULLY understand from reading several tutorials).

Streams seems to suggest that input can be treated continously if
needed. Is this true?

So far as I know, I can only get a stream to "flow" when there is a
'\r'. At that point the '\r' is turned into a '\n' and the whole
stream is sent to some abstract area that is now only accessible to my
programs (meanwhile, other data is still piling into the input
"staging" area of the stream, waiting for another '\r' to free them-
allow them to flow).

Is this an accurate observation of C's model? Is there anyway I can
get more of a continuous stream action, instead of this '\r' triggered
stream? I am guessing there might be, but it would be a
C-extension!?!?
By the way, the first couple examples using getchar in K&R2 rely on
comparing (c=getchar()) with EOF. But, what happened to the final '\r'
that actually releases the EOF from it's input staging area? Does that
'\r' stay there waiting to release the next char that comes to the
input to the stream? Does that '\r' get converted to '\n' and sent on
it's way ready for immediate reading by an input function? Does that
'\n' disappear because of some relationship with EOF?
A link to comprehensive tutorials will be appreciated.

Nov 14 '05 #1
11 1786
"Kobu" <ko********@gma il.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
I have a question about C's abstract "streams" (that I can't seem to
FULLY understand from reading several tutorials).

Streams seems to suggest that input can be treated continously if
needed. Is this true?
Yes, in the sense that i/o is implemented as a
continuous 'stream' of characters. ("continous"
being interruptible by an error condition or an
'end of file' indicator).
So far as I know, I can only get a stream to "flow" when there is a
'\r'.
No. A stream of characters need not contain a particular
value character. '\r' (or '\n', etc.) is just another
character.
At that point the '\r' is turned into a '\n'
Character translations (if any) are defined by a particular
implementation (probably most well known is the 'CR/LF' to/
form '\n' translation in DOS and Windows). Also note that this
'translation' is only applicable to streams opened with 'text
mode' (the default). Streams open in "binary mode" (expressed
with second argument to 'fopen()' of "b"), render the characters
as they are delivered by the attached device, with no 'translations'
at all.
and the whole
stream is sent to some abstract area that is now only accessible to my
programs (meanwhile, other data is still piling into the input
"staging" area of the stream, waiting for another '\r' to free them-
allow them to flow).
You're asking about 'buffering', which is defined by an implementation.
E.g. many/most systems where the standard stream 'stdin' is attached
to a keyboard, use 'line buffering', where the data is not sent to
the program until e.g. an 'Enter' or 'return' key is pressed. But this
is not required by the language.

Is this an accurate observation of C's model?
No, it seems to be your observation of a particular implementation
of C on a particular platform. This is admittedly a very common
behavior.
Is there anyway I can
get more of a continuous stream action, instead of this '\r' triggered
stream?
You're asking about 'nonblocking input', which is not required
(nor prohibited) by the language.
I am guessing there might be, but it would be a
C-extension!?!?


Yes, library extensions are the typical method for doing this
on platforms where it's applicable, e.g. those where 'stdin'
is attached to a line-buffered keyboard input. An implementation
or OS might also provide a facility (via another extension) to disable
'line buffering'. Check your compiler documentation.

-Mike
Nov 14 '05 #2
Mike Wahler wrote:
No. A stream of characters need not contain a particular
value character. '\r' (or '\n', etc.) is just another
character.


Text streams are composed of lines, which are newline terminated.

--
pete
Nov 14 '05 #3

"pete" <pf*****@mindsp ring.com> wrote in message
news:41******** ***@mindspring. com...
Mike Wahler wrote:
No. A stream of characters need not contain a particular
value character. '\r' (or '\n', etc.) is just another
character.


Text streams are composed of lines, which are newline terminated.


I wrote 'stream', not 'text stream'.

Anyway, the below excerpt from 9899 indicates to me that
a text stream may contain zero or more newline characters.

7.19.2 Streams

2 A text stream is an ordered sequence of characters composed
into lines, each line consisting of zero or more characters
plus a terminating new-line character. Whether the last line
requires a terminating new-line character is implementation-
defined.

-Mike
Nov 14 '05 #4
pete wrote:
Mike Wahler wrote:
No. A stream of characters need not contain a particular
value character. '\r' (or '\n', etc.) is just another
character.


Text streams are composed of lines, which are newline terminated.


No, they are just sequences of characters, which should include at
least one newline character at the end. There is no intrinsic
reason to limit the count of characters between newline chars in
C. It is just a useful convention to normally keep this below 72
or 80.

The fact that routines such as fgets deliver newline separated
chunks is again not germane to what a stream is.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #5
CBFalconer wrote:

pete wrote:
Mike Wahler wrote:
No. A stream of characters need not contain a particular
value character. '\r' (or '\n', etc.) is just another
character.


Text streams are composed of lines, which are newline terminated.


No


N869
7.19.2 Streams
[#2] A text stream is an ordered sequence of characters
composed into lines each line consisting of zero or more
characters plus a terminating new-line character.

--
pete
Nov 14 '05 #6
pete wrote:
CBFalconer wrote:
pete wrote:
Mike Wahler wrote:
No. A stream of characters need not contain a particular
value character. '\r' (or '\n', etc.) is just another
character .

Text streams are composed of lines, which are newline terminated.


No

N869
7.19.2 Streams
[#2] A text stream is an ordered sequence of characters
composed into lines each line consisting of zero or more
characters plus a terminating new-line character.

Selective reading pete? Mike didn't specify text streams and the
same section you quote says..

[#3] A binary stream is an ordered sequence of characters
that can transparently record internal data. Data read in
from a binary stream shall compare equal to the data that
were earlier written out to that stream, under the same
implementation.
--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #7
Joe Wright wrote:

pete wrote:
CBFalconer wrote:
pete wrote:

Mike Wahler wrote:
>No. A stream of characters need not contain a particular
>value character. '\r' (or '\n', etc.) is just another
>character .

Text streams are composed of lines, which are newline terminated.

No

N869
7.19.2 Streams
[#2] A text stream is an ordered sequence of characters
composed into lines each line consisting of zero or more
characters plus a terminating new-line character.

Selective reading pete?


I'm just saying that text streams are made of lines.
If you don't want know that, you don't have to.

--
pete
Nov 14 '05 #8

"pete" <pf*****@mindsp ring.com> wrote in message
news:41******** ***@mindspring. com...
CBFalconer wrote:

pete wrote:
Mike Wahler wrote:

> No. A stream of characters need not contain a particular
> value character. '\r' (or '\n', etc.) is just another
> character.

Text streams are composed of lines, which are newline terminated.


No


N869
7.19.2 Streams
[#2] A text stream is an ordered sequence of characters
composed into lines each line consisting of zero or more
characters plus a terminating new-line character.


You omitted:

Whether the last line requires a terminating new-line character
is implementation-defined.

-Mike
Nov 14 '05 #9

"pete" <pf*****@mindsp ring.com> wrote in message
news:41******** ***@mindspring. com...
Joe Wright wrote:

pete wrote:
CBFalconer wrote:

>pete wrote:
>
>>Mike Wahler wrote:
>>
>>
>>>No. A stream of characters need not contain a particular
>>>value character. '\r' (or '\n', etc.) is just another
>>>character .
>>
>>Text streams are composed of lines, which are newline terminated.
>
>No
N869
7.19.2 Streams
[#2] A text stream is an ordered sequence of characters
composed into lines each line consisting of zero or more
characters plus a terminating new-line character.
Selective reading pete?


I'm just saying


The ISO C standard says
that text streams are made of lines.
that a text stream may or may not contain one or more
newline characters.
If you don't want know that, you don't have to.


Back at ya. :-)

-Mike
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
7407
by: dover | last post by:
For the code, outputfile << *p << endl; Someone suggests: Don't use endl here; it is flushing output stream every time. Use plain '\n'. What's the difference of using "endl" and "\n" above? What's the meaning of flushing output stream? Isn't that what we want? Thanks!
8
2723
by: bonj | last post by:
hello I hope somebody can help me get my head around this area of 'stream' programming... I know that streams are very fashionable nowadays so hopefully there'll be lots of replies. ;-) Basically I have an operation which the input and output for are streams - a function which receives a certain 'chunk' of data each time it runs, and it...
145
6214
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two programs: /*** a.c ***/
4
6215
by: floppyzedolfin | last post by:
Hello! I'm actually encoding an encryption / decryption program. The encryption programes takes a file path in parameter, and encrypts the contents of the file and stores that into another file. I'm using AES for it is quick, and RSA to encrypt AES, to transmit AES keys (it'll run on two separate computers). Please notice that - this is...
9
3353
by: andrew.smith.cpp | last post by:
hi, whts the difference between the std::endl or "\n" ? because both do the same work Thanks
0
7895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5701
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3818
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1433
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.