Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: EOF issue |
| Date | 2015-11-20 17:57 -0800 |
| Organization | None to speak of |
| Message-ID | <ln1tbkcdxb.fsf@kst-u.example.com> (permalink) |
| References | <39e3aac5-5b96-4a07-9078-4a6c0207e0df@googlegroups.com> <87poz7y3km.fsf@bsb.me.uk> <fff30e38-fe45-48c7-81e7-f2713fbd67d0@googlegroups.com> <n2icmg$8s1$1@dont-email.me> |
Richard Heathfield <rjh@cpax.org.uk> writes:
[...]
> To get you started, here is an echo program:
>
> #include <stdio.h>
>
> int main(void)
> {
> int c = 0;
> while((c = getchar()) != EOF)
> {
> putchar(c);
> }
> return 0;
> }
>
> This will copy the program's input to its output, and it has the
> advantage of being very, very simple (and correct).
And it's a simple version of "cat", not "echo".
> Use it (compile and run it) to figure out how to signal an end-of-file
> condition from standard input (as outlined above).
On Unix-like systems (including Mac OSX), end-of-file while reading from
a keyboard is signalled by typing Ctrl-D once at the beginning of a line
(i.e., either as the first input or immediately after typing <Enter>)
*or* by typing Ctrl-D twice other than at the beginning of a line. The
latter is uncommon; you usually want complete lines of input.
You can also provide input in batch mode. For example, you can provide
your program with a single line of input by typing:
echo hello | ./your_program
or multiple lines like this:
( echo "line one" ; echo "line two" ) | ./your_program
or
printf "line one\nline two\n" | ./your_program
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
EOF issue Alla _ <modelling.data@gmail.com> - 2015-11-18 01:03 -0800
Re: EOF issue Ian Collins <ian-news@hotmail.com> - 2015-11-18 22:55 +1300
Re: EOF issue Alla _ <modelling.data@gmail.com> - 2015-11-18 02:54 -0800
Re: EOF issue "Osmium" <r124c4u102@comcast.net> - 2015-11-18 06:48 -0600
Re: EOF issue Lőrinczy Zsigmond <nospam@for.me> - 2015-11-18 16:35 +0100
Re: EOF issue "Osmium" <r124c4u102@comcast.net> - 2015-11-18 12:58 -0600
Re: EOF issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-18 16:31 +0000
Re: EOF issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-18 11:00 +0000
Re: EOF issue Alla _ <modelling.data@gmail.com> - 2015-11-18 07:31 -0800
Re: EOF issue Richard Heathfield <rjh@cpax.org.uk> - 2015-11-18 17:34 +0000
Re: EOF issue Keith Thompson <kst-u@mib.org> - 2015-11-20 17:57 -0800
Re: EOF issue Barry Schwarz <schwarzb@dqel.com> - 2015-11-18 11:44 -0800
Re: EOF issue alla.rashitova@gmail.com - 2015-11-19 00:47 -0800
Re: EOF issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 05:56 -0800
Re: EOF issue Richard Heathfield <rjh@cpax.org.uk> - 2015-11-19 16:22 +0000
Re: EOF issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-18 21:09 +0000
csiph-web