|
From: Per W. <pw...@ia...> - 2006-01-11 02:38:58
|
But Gary doesn't want more than one command. He really doesn't want any
commands at all to be performed in the body of the for loop. It's all in
the side effects of the second and third loop expression...
The program is just expected to receive characters (2nd expression) and
count them (3rd expression) and then - after the loop has finished on
end-of-file - print out the total.
Besides looking at the syntactics of the code, the indentation is a hint
:)
/Per W
On Tue, 10 Jan 2006, lordSauron wrote:
> On 1/10/06, Per Westermark <pw...@ia...> wrote:
> > Short note: "empty" loops are quite common, i.e. all the side effects are
> > in the second and third expression.
> >
> > /Per W
> >
> > On Tue, 10 Jan 2006 dz...@su... wrote:
> >
> > > Mr. Lefebvre,
> > >
> > > In you "for()" loop you left out the "{" & "}" braces
> > > defining your loop.
> > >
> > > Try the following changes listed below. This worked
> > > for me.
> > >
> > > ..Bob
> > >
> > > #include <stdio.h>
> > > #include <stdlib.h>
> > >
> > > main()
> > > {
> > > long nc;
> > > nc=0;
> > >
> > > for (nc=0; getchar()!=EOF; ++nc)
> > > { //opening brace for "for()" loop.
> > > printf("%ld\n",nc);
> > > system("Pause");
> > > } //closing brace for "for()" loop.
> > >
> > > return 0;
> > > }
>
> Try this:
>
> for (/*whatever you had here.... I'm lazy - srry*/) printf();
>
> instead of for(); printf();, which treats them as seperate statements.
> If you want more that one command in the loop, you must use brackets
> (unless there's something I don't know about, in which case you will
> tell me, right?)
>
> --
> ========== GCv3.12 ==========
> GCS d-(++) s+: a? C++ UL+>++++ P+
> L++ E--- W+(+++) N++ o? K? w--- O? M+
> V? PS- PE+ Y-(--) PGP- t+++ 5? X R tv-- b+
> DI+++ D+ G
|