Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Markus Wichmann <nullplan@gmx.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: stream functions |
| Date | 2012-02-14 21:50 +0100 |
| Organization | 1&1 Internet AG |
| Message-ID | <i2uq09-p35.ln1@voyager.wichi.de.vu> (permalink) |
| References | (4 earlier) <4f32e0fa$0$1300$bbae4d71@news.suddenlink.net> <jguo9o$lop$1@reader1.panix.com> <4f32f90d$0$32645$bbae4d71@news.suddenlink.net> <jguvo0$r5i$1@reader1.panix.com> <355b5dc6-d2aa-4edf-a01a-1afa400f8cca@k10g2000yqk.googlegroups.com> |
On 13.02.2012 11:14, Nick Keighley wrote:
> On Feb 8, 11:16 pm, John Gordon <gor...@panix.com> wrote:
>> In <4f32f90d$0$32645$bbae4...@news.suddenlink.net> "Bill Cunningham" <nos...@nspam.invalid> writes:
>
> <snip>
>
>>> Loops is something I've never really caught onto in C.
>>
>> Loops are a basic concept in almost any programming language;
>
> I think some functional languages manage without them. Certainly Lisp,
> C++, Python programs can be written that don't use loops.
>
Ah, functional languages! The next big hype after object oriented
languages. Just wait till they notice that functional languages also
aren't the answer to the universe and everything.
>> perhaps you should brush up on them in C.
>
> to put it mildly! Loops are absolutly fundamental to a language like C.
Theoretically, all loops can be replaced by recursive functions. But
that could become a PITA. For instance, finding x, y and z such that for
a 3D-array a you get a[x][y][z] == c. With loops:
int find_in(int*** a, int* x, int* y, int* z, int c)
{
for (*x = 0; *x < MAX_X; ++*x)
for (*y = 0; *y < MAX_Y; ++*y)
for (*z = 0; *z < MAX_Z; ++*z)
if (a[*x][*y][*z] == c)
return 1;
return 0;
}
Without loops:
int find_in_z(int*** a, int* x, int* y, int* z, int c)
{
if (*z >= MAX_Z) return 0;
if (a[*x][*y][*z] == c) return 1;
++*z;
return find_in_z(a, x, y, z, c);
}
int find_in_y(int*** a, int* x, int* y, int* z, int c)
{
if (*y >= MAX_Y) return 0;
if (find_in_z(a, x, y, z, c)) return 1;
++*y;
return find_in_y(a, x, y, z, c);
}
int find_in_x(int*** a, int* x, int* y, int* z, int c)
{
if (*x >= MAX_X) return 0;
if (find_in_y(a, x, y, z, c)) return 1;
++*x;
return find_in_x(a, x, y, z, c);
}
int find_in(int*** a, int* x, int* y, int* z, int c)
{
*x = *y = *z = 0;
return find_in_x(a, x, y, z, c);
}
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 16:50 -0500
Re: stream functions John Gordon <gordon@panix.com> - 2012-02-07 23:07 +0000
Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 18:31 -0500
Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 18:33 -0500
Re: stream functions Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-02-08 02:39 +0100
Re: stream functions Keith Thompson <kst-u@mib.org> - 2012-02-07 18:39 -0800
Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 22:36 -0500
Re: stream functions Nobody <nobody@nowhere.com> - 2012-02-08 19:43 +0000
Re: stream functions Barry Schwarz <schwarzb@dqel.com> - 2012-02-07 21:01 -0800
Re: stream functions John Gordon <gordon@panix.com> - 2012-02-08 15:13 +0000
Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-08 15:54 -0500
Re: stream functions John Gordon <gordon@panix.com> - 2012-02-08 21:09 +0000
Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-08 17:37 -0500
Re: stream functions John Gordon <gordon@panix.com> - 2012-02-08 23:16 +0000
Re: stream functions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-13 02:14 -0800
Re: stream functions James Kuyper <jameskuyper@verizon.net> - 2012-02-13 05:53 -0500
Re: stream functions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-13 03:23 -0800
Re: stream functions Markus Wichmann <nullplan@gmx.net> - 2012-02-14 21:50 +0100
Re: stream functions "Heinrich Wolf" <invalid@invalid.invalid> - 2012-02-09 10:45 +0100
Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-09 22:37 -0500
Re: stream functions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-13 02:17 -0800
Re: stream functions gordonb.qxgs4@burditt.org (Gordon Burditt) - 2012-02-13 01:03 -0600
Re: stream functions Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-13 08:23 +0000
Re: stream functions Keith Thompson <kst-u@mib.org> - 2012-02-13 02:06 -0800
Re: stream functions David Thompson <dave.thompson2@verizon.net> - 2012-02-18 23:12 -0500
csiph-web