|
From: <dz...@su...> - 2006-01-10 16:57:32
|
Mr=2E Lefebvre,
In you "for()" loop you left out the "{" & "}" braces
defining your loop=2E
Try the following changes listed below=2E This worked
for me=2E
=2E=2EBob
#include <stdio=2Eh>
#include <stdlib=2Eh>
main()
{
long nc;
nc=3D0;
for (nc=3D0; getchar()!=3DEOF; ++nc)
{ //opening brace for "for()" loop=2E
printf("%ld\n",nc);
system("Pause");
} //closing brace for "for()" loop=2E
return 0;
}
--------------------------------------------------------------------Fr
om: dev-cpp-users-admin@lists=2Esourceforge=2Enet
[mailto:dev-cpp-users-admin@lists=2Esourceforge=2Enet] On Behalf Of Gary
Lefebvre
Sent: Tuesday, January 10, 2006 9:32 AM
To: dev-cpp-users@lists=2Esourceforge=2Enet
Subject: [Dev-C++] Loops
#include <stdio=2Eh>
#include <stdlib=2Eh>
main()
{
long nc;
nc=3D0;
for (nc=3D0; getchar()!=3DEOF; ++nc);
printf("%ld\n",nc);
system("Pause");
return 0;
}
No matter what loop option I try I have the same result=2E The loop
does not terminate when, after entering text, I press the enter key=2E
The command window hangs=2E The loop will not terminate to proceed to
the rest of the code=2E
|
|
From: Ray K. <kul...@wr...> - 2006-01-11 04:29:57
|
As kalb mentioned, you can send it an end of file character using an
escape sequence to terminate the loop.
Another way would be to change the test to
for (nc = 0; '\n' != getchar(); ++nc);
That will test for a newline instead of EOF, which should make the loop
terminate when you hit the enter key.
"Gary Lefebvre" <gar...@co...> wrote:
> #include <stdio.h>
> #include <stdlib.h>
> main()
> {
> long nc;
> nc=0;
> for (nc=0; getchar()!=EOF; ++nc);
> printf("%ld\n",nc);
> system("Pause");
> return 0;
> }
> No matter what loop option I try I have the same result. The loop does
> not
> terminate when, after entering text, I press the enter key. The command
> window hangs. The loop will not terminate to proceed to the rest of the
> code.
|
|
From: Per W. <pw...@ia...> - 2006-01-10 19:00:59
|
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;
> }
>
>
>
> --------------------------------------------------------------------Fr
> om: dev...@li...
> [mailto:dev...@li...] On Behalf Of Gary
> Lefebvre
> Sent: Tuesday, January 10, 2006 9:32 AM
> To: dev...@li...
> Subject: [Dev-C++] Loops
>
>
> #include <stdio.h>
> #include <stdlib.h>
>
> main()
> {
> long nc;
> nc=0;
>
> for (nc=0; getchar()!=EOF; ++nc);
> printf("%ld\n",nc);
> system("Pause");
>
> return 0;
> }
>
>
> No matter what loop option I try I have the same result. The loop
> does not terminate when, after entering text, I press the enter key.
> The command window hangs. The loop will not terminate to proceed to
> the rest of the code.
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored
|
|
From: lordSauron <lor...@gm...> - 2006-01-10 19:31:00
|
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=3D0;
> >
> > for (nc=3D0; getchar()!=3DEOF; ++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?)
--
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D GCv3.12 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 e* h- !r !y
=3D=3D=3D=3D=3D=3D=3D=3D=3D END GCv3.12 =3D=3D=3D=3D=3D=3D=3D=3D
|
|
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
|