Greetings all,
Here is another incredibly silly question. I feel foolish asking it, but
i've no other choice. I was going through K&R2 and at section 1.5.2
(Character Counting), I decided to try out the program:
/* count characters in input; 1st version */
#include <stdio.h>
int main(void)
{
long nc;
nc=0;
while(getchar()!=EOF)
++nc;
printf("%ld\n",nc);
return 0;
}
after compiling it, I ran it. I typed in some letters and numbers and they
were repeated on the screen (as expected). But then what? How do I get the
count of the characters typed? I tried ctrl-d (I get a diamond), ctrl-z
(program terminates), and ctrl-c (program terminates). What am I doing wrong
or what am I understanding wrong? Any help is much appreciated.
Best,
newby2c
--
Tech Support: "How may I help you?"
Customer: "I'm writing my first email."
Tech Support: "Ok, what seems to be the problem?"
Customer: "Well I can get the 'a'. But how do I put the circle around it?" 41 2072
[ snip ]
Sorry, I forgot to mention that I using a win98 box (if that even matters).
newby2c
Have u tried the input -1 ??????
newby2c wrote: [ snip ]
Sorry, I forgot to mention that I using a win98 box (if that even matters).
newby2c
newby2c wrote: [ snip ]
Sorry, I forgot to mention that I using a win98 box (if that even matters).
Start your program, type your line,
then hit the enter key,
then your EOF, which is ctrl-z on my machine,
then hit the enter key again. my******@lucent.com wrote:
[ Do not top-post. Corrected. newby2c wrote:
Sorry, I forgot to mention that I using a win98 box (if that even matters).
Have u tried the input -1 ??????
May I ask whatever gave you the idea that this could be useful? All it
does is return, subsequently, '-', '1', ' ', and six times '?' (rather
excessive, IYAM). Since all of these are in the required execution
character set, this input is in fact guaranteed _not_ to end the loop.
What the OP need to do (as usual, *sigh*), is to RTFFAQ. This question
is, unfortunately, not currently in the web version, so I can't link to
it (Steve: I think it should be, this is _very_ frequent), but it _is_
in the version which is posted here regularly; it's question 12.1b.
Richard
"newby2c" <se******@juno.com> writes:
[...] /* count characters in input; 1st version */
#include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("%ld\n",nc); return 0; }
after compiling it, I ran it. I typed in some letters and numbers and they were repeated on the screen (as expected). But then what? How do I get the count of the characters typed? I tried ctrl-d (I get a diamond), ctrl-z (program terminates), and ctrl-c (program terminates). What am I doing wrong or what am I understanding wrong? Any help is much appreciated.
The program should read input characters until it hits an EOF
condition. How that EOF condition is triggered is system-specific.
You mentioned elsethread that you're running on a Windows system. You
should be able to trigger and EOF by entering control-Z on a line by
itself. The program should then print the number of characters
entered and terminate. (Perhaps you didn't notice the number?) You
should also be able to redirect the program's input from a text file;
EOF will then be triggered when the program reaches the end of the
file. Other systems will behave differently (which makes this
paragraph mildly off-topic).
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. my******@lucent.com writes: newby2c wrote: [ snip ]
Sorry, I forgot to mention that I using a win98 box (if that even matters).
newby2c
Have u tried the input -1 ??????
Please don't top-post. Your response should follow any quoted text,
not precede it.
I'm afraid you suggestion doesn't make any sense. EOF (which is
typically equal to -1, but it doesn't have to be) is the value
returned by getchar() when it reaches the end of the input. It's not
a character value. Even if it were, entering "-1" would cause
getchar() to return '-' followed by '1'.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
newby2c wrote on 10/08/04 : /* count characters in input; 1st version */
#include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("%ld\n",nc); return 0; }
after compiling it, I ran it. I typed in some letters and numbers and they were repeated on the screen (as expected). But then what? How do I get the count of the characters typed? I tried ctrl-d (I get a diamond),
This would be OK on a Unixoid machine.
ctrl-z (program terminates),
This is OK on a DOS-Windows machine. You are probably using Dev-C++,
and the Dos-box close instantly. Just add a 'pause' before the return
of main():
getchar();
and ctrl-c (program terminates).
Don't do that.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
newby2c wrote:
.... snip ... #include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("%ld\n",nc); return 0; }
You get no special prizes for eliding blanks. The following is
the same program, but legible:
#include <stdio.h>
int main(void)
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
return 0;
}
Admittedly, there are very few added blanks, but get in the habit. after compiling it, I ran it. I typed in some letters and numbers and they were repeated on the screen (as expected). But then what? How do I get the count of the characters typed? I tried ctrl-d (I get a diamond), ctrl-z (program terminates), and ctrl-c (program terminates). What am I doing wrong or what am I understanding wrong? Any help is much appreciated.
The ctrl-z caused the system to generate EOF, execute the printf,
and terminate. The fact that you are confused makes me suspect
you are using some form of IDE, rather than a command line
compiler. The IDE is closing the window when (after) the program
exits.
Compile to disk (see your compiler systems documentation) and then
run the resultant program. Or, better, learn to use the command
line for compilation and running. This usually means (on windows
systems) using a dosbox. Some IDEs have a way to show the user
window after the program exits, Borlands among them.
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
CBFalconer wrote: newby2c wrote:
You get no special prizes for eliding blanks. The following is the same program, but legible:
while (getchar() != EOF) ++nc;
I always use a compound statement in loops:
while (getchar() != EOF) {
++nc;
}
"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41****************@news.individual.net... What the OP need to do (as usual, *sigh*), is to RTFFAQ. This question is, unfortunately, not currently in the web version, so I can't link to it (Steve: I think it should be, this is _very_ frequent), but it _is_ in the version which is posted here regularly; it's question 12.1b.
Richard
Thank you. I will look for it when it is posted again.
newby2c
"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com... Start your program, type your line, then hit the enter key, then your EOF, which is ctrl-z on my machine, then hit the enter key again.
Thanks. I tried that. Here is what happens:
I run the program.
I type in some words and use spaces and tabs.
I hit enter key.
Caret starts at new line.
I then hit ctrl-z.
Nothing happens!
I hit ctrl-z again and the program terminates, but the DOS box remains open.
newby2c
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org... The program should read input characters until it hits an EOF condition. How that EOF condition is triggered is system-specific.
You mentioned elsethread that you're running on a Windows system. You should be able to trigger and EOF by entering control-Z on a line by itself. The program should then print the number of characters entered and terminate. (Perhaps you didn't notice the number?) You should also be able to redirect the program's input from a text file; EOF will then be triggered when the program reaches the end of the file. Other systems will behave differently (which makes this paragraph mildly off-topic).
Thank you. But even ctrl-z on it's own line does not work. The first time I
enter ctrl-z, nothing happens. If I do ctrl-z a second time, the program
terminates with the DOS box remaining open.
newby2c
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr...
[ snip ] This is OK on a DOS-Windows machine. You are probably using Dev-C++, and the Dos-box close instantly. Just add a 'pause' before the return of main():
getchar();
and ctrl-c (program terminates).
Don't do that.
Thanks for the suggestion. Yes, I am using Dev-C++. However I do not use the
IDE to run my programs. I run everything from the command line in a DOS
window. Unfortunately, your suggestion did not work. I get the same results
as mentioned in my previously replies to others in this thread.
newby2c
newby2c wrote on 10/08/04 : "Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message news:mn***********************@YOURBRAnoos.fr... [ snip ] This is OK on a DOS-Windows machine. You are probably using Dev-C++, and the Dos-box close instantly. Just add a 'pause' before the return of main():
getchar();
I am using Dev-C++. However I do not use the IDE to run my programs. I run everything from the command line in a DOS window. Unfortunately, your suggestion did not work. I get the same results as mentioned in my previously replies to others in this thread.
I think you must hit <ctrl-z> <enter>
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
"CBFalconer" <cb********@yahoo.com> wrote in message
news:41***************@yahoo.com... You get no special prizes for eliding blanks. The following is the same program, but legible:
#include <stdio.h>
int main(void) { long nc;
nc = 0; while (getchar() != EOF) ++nc; printf("%ld\n", nc); return 0; }
Admittedly, there are very few added blanks, but get in the habit.
Thanks for the advice.
The ctrl-z caused the system to generate EOF, execute the printf, and terminate. The fact that you are confused makes me suspect you are using some form of IDE, rather than a command line compiler. The IDE is closing the window when (after) the program exits.
No. I do indeed use the command line from a DOS window to run programs.
Compile to disk (see your compiler systems documentation) and then run the resultant program. Or, better, learn to use the command line for compilation and running. This usually means (on windows systems) using a dosbox. Some IDEs have a way to show the user window after the program exits, Borlands among them.
See above.
newby2c
newby2c wrote:
.... snip ... Thank you. But even ctrl-z on it's own line does not work. The first time I enter ctrl-z, nothing happens. If I do ctrl-z a second time, the program terminates with the DOS box remaining open.
That sounds like a fault in the system, probably Microsofts. Try
ctrl-z return.
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
On Mon, 9 Aug 2004 22:44:49 -0400, "newby2c" <se******@juno.com>
wrote: Greetings all,
Here is another incredibly silly question. I feel foolish asking it, but i've no other choice. I was going through K&R2 and at section 1.5.2 (Character Counting), I decided to try out the program:
/* count characters in input; 1st version */
#include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("%ld\n",nc); return 0; }
after compiling it, I ran it. I typed in some letters and numbers and they were repeated on the screen (as expected). But then what? How do I get the count of the characters typed? I tried ctrl-d (I get a diamond), ctrl-z (program terminates), and ctrl-c (program terminates). What am I doing wrong or what am I understanding wrong? Any help is much appreciated.
Best, newby2c
Here in windows xp <ctrl-z>==EOF so if I push some chars <ctrl-z> and
'\n' the prog print the correnct number of char (less the last '\n').
I think you could resolve your problem if you write in the code
printf("%ld\n\n", nc); /* note \n\n */
and use <ctrl-z> for end.
"CBFalconer" <cb********@yahoo.com> wrote in message
news:41***************@yahoo.com... That sounds like a fault in the system, probably Microsofts. Try ctrl-z return.
Hiya CB,
I just tried your suggestion. No good.
Ran prog.
typed Hello, my name is newbyc (then ctrl-z on the same line).
Then hit enter.
Prog. terminates with DOS window still open (I added getchar();).
See code below:
/* count characters in input; 1st version */
#include <stdio.h>
int main(void)
{
long nc;
nc=0;
while(getchar()!=EOF)
++nc;
printf("%ld\n",nc);
getchar();
return 0;
}
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr... I think you must hit <ctrl-z> <enter>
Hi Emmanuel,
If you mean to hit <ctrl-z> *and* <enter> at the *same time*, I tried that.
Unfortunately, that did not work either.
"RoSsIaCrIiLoIA" <n@esiste.ee> wrote in message
news:9a********************************@4ax.com... Here in windows xp <ctrl-z>==EOF so if I push some chars <ctrl-z> and '\n' the prog print the correnct number of char (less the last '\n'). I think you could resolve your problem if you write in the code printf("%ld\n\n", nc); /* note \n\n */ and use <ctrl-z> for end.
Thanks R...,
I just tried that. Still no good. Damn this is frustrating.
newby2c
newby2c <se******@juno.com> scribbled the following: "Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message news:mn***********************@YOURBRAnoos.fr... I think you must hit <ctrl-z> <enter>
Hi Emmanuel,
If you mean to hit <ctrl-z> *and* <enter> at the *same time*, I tried that. Unfortunately, that did not work either.
No, he meant first hit <ctrl-z> and then hit <enter>.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To err is human. To really louse things up takes a computer."
- Anon
newby2c wrote on 10/08/04 : "Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message news:mn***********************@YOURBRAnoos.fr... I think you must hit <ctrl-z> <enter>
Hi Emmanuel,
If you mean to hit <ctrl-z> *and* <enter> at the *same time*, I tried that. Unfortunately, that did not work either.
No. Hit them in sequence.
<ctrl-z>
then
<enter>
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
On Tue, 10 Aug 2004 10:55:25 -0400, "newby2c" wrote: "RoSsIaCrIiLoIA" <n@esiste.ee> wrote in message news:9a********************************@4ax.com.. . Here in windows xp <ctrl-z>==EOF so if I push some chars <ctrl-z> and '\n' the prog print the correnct number of char (less the last '\n'). I think you could resolve your problem if you write in the code printf("%ld\n\n", nc); /* note \n\n */ and use <ctrl-z> for end.
Thanks R...,
I just tried that. Still no good. Damn this is frustrating.
newby2c
yes, this seems goes ok in Windows95
#include <stdio.h>
int main(void)
{
long nc;
nc=0;
while(getchar()!=EOF)
++nc;
printf("\n\n%ld\n",nc); /* note /n/n */
return 0;
}
newby2c wrote: "CBFalconer" <cb********@yahoo.com> wrote in message
That sounds like a fault in the system, probably Microsofts. Try ctrl-z return.
I just tried your suggestion. No good. Ran prog. typed Hello, my name is newbyc (then ctrl-z on the same line). Then hit enter. Prog. terminates with DOS window still open (I added getchar();). See code below:
No, line, enter, ctl-z, enter.
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:cf**********@oravannahka.helsinki.fi... No, he meant first hit <ctrl-z> and then hit <enter>.
Thanks Joona,
I had already tried that and it did not work to which I posted in an earlier
message. That is why I thought hit meant to hit them together.
newby2c
"CBFalconer" <cb********@yahoo.com> wrote in message
news:41***************@yahoo.com... No, line, enter, ctl-z, enter.
Thanks again.
Ran prog. Typed line. Hit <enter> (the caret moved to new line).
Hit <ctrl-z>. Prog. terminates.
Never had a chance to hit <enter>.
This was the program in it's original form (without getchar();).
With the getchar(); in place just before the return 0; I type some words,
hit <enter>, then hit <ctrl-z>, (prog. does *not* terminate), lastly I hit
<enter>. The prog. terminates, but there is still no output.
newby2c
newby2c
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr... No. Hit them in sequence. <ctrl-z> then <enter>
Hi Emmanuel,
I had already tried that to no avail.
newby2c
"RoSsIaCrIiLoIA" <n@esiste.ee> wrote in message
news:8m********************************@4ax.com... yes, this seems goes ok in Windows95
#include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("\n\n%ld\n",nc); /* note /n/n */ return 0; }
That's it! It worked! I added the two newline (\n\n) characters to the
*front*, before the long integer (as seen above). I ran the program. Typed
in "this is a test" (without quotes). Hit <ctrl-z>. The number 14 appears,
and the prog. terminates. Excellent!! I don't know *why* it works, but it
does. Anyway, this is a good one for the books.
Thanks R...!!! Thank you all for your input. Now if someone could explain
why this needs to be done this way, I would have gained a very valuable
lesson.
newby2c
newby2c wrote on 10/08/04 : #include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("\n\n%ld\n",nc); /* note /n/n */ return 0; }
That's it! It worked! I added the two newline (\n\n) characters to the *front*, before the long integer (as seen above). I ran the program. Typed in "this is a test" (without quotes). Hit <ctrl-z>. The number 14 appears, and the prog. terminates. Excellent!! I don't know *why* it works, but it does. Anyway, this is a good one for the books.
Thanks R...!!! Thank you all for your input. Now if someone could explain why this needs to be done this way, I would have gained a very valuable lesson.
I can't explain this. All I have seen is that yes, there is a problem
with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message
news:mn***********************@YOURBRAnoos.fr... I can't explain this. All I have seen is that yes, there is a problem with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.
Oh, so it's a compiler thing? Thanks. Do the Dev's there know about this
particular problem?
newby2c
"newby2c" <se******@juno.com> writes: "Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote in message news:mn***********************@YOURBRAnoos.fr... I can't explain this. All I have seen is that yes, there is a problem with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.
Oh, so it's a compiler thing? Thanks. Do the Dev's there know about this particular problem?
More likely it's a runtime library thing, but the library is probably
bundled with the compiler. In any case, it's not really a question
for comp.lang.c; perhaps one of the Windows or MS-DOS programming
groups can help.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
newby2c wrote: "pete" <pf*****@mindspring.com> wrote in message news:41***********@mindspring.com... Start your program, type your line, then hit the enter key, then your EOF, which is ctrl-z on my machine, then hit the enter key again. Thanks. I tried that.
Your written account indicates that you tried something else.
Here is what happens:
I run the program. I type in some words and use spaces and tabs. I hit enter key. Caret starts at new line. I then hit ctrl-z. Nothing happens!
I hit ctrl-z again
That's not what I said to do.
Try hitting the enter key a second time, after ctrl-z,
instead of hitting ctrl-z a second time.
and the program terminates, but the DOS box remains open.
--
pete
"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com... That's not what I said to do. Try hitting the enter key a second time, after ctrl-z, instead of hitting ctrl-z a second time.
I had already tried that method and wrote back to the thread that I never
get the chance to hit the <enter> key a second time (after <ctrl-z>). The
program terminates. Anyway, the problem has been detected (Run-Time Library
problem using Dev-C++ compiler, I think). In case you hadn't followed the
full thread, I have to add two newline characters at the beginning of the
printf statement:
printf("\n\n%ld",nc);
For some reason this actually works. Although at the moment I have no idea
why.
newby2c
newby2c wrote: "RoSsIaCrIiLoIA" <n@esiste.ee> wrote in message
yes, this seems goes ok in Windows95
#include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("\n\n%ld\n",nc); /* note /n/n */ return 0; }
That's it! It worked! I added the two newline (\n\n) characters to the *front*, before the long integer (as seen above). I ran the program. Typed in "this is a test" (without quotes). Hit <ctrl-z>. The number 14 appears, and the prog. terminates. Excellent!! I don't know *why* it works, but it does. Anyway, this is a good one for the books.
Thanks R...!!! Thank you all for your input. Now if someone could explain why this needs to be done this way, I would have gained a very valuable lesson.
It shouldn't make a difference. There is something wrong with
your system. What is it, complete with what compiler, etc. you
are using.
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
On Tue, 10 Aug 2004 20:57:44 +0200, Emmanuel Delahaye wrote: newby2c wrote on 10/08/04 : #include <stdio.h>
int main(void) { long nc;
nc=0; while(getchar()!=EOF) ++nc; printf("\n\n%ld\n",nc); /* note /n/n */ return 0; }
That's it! It worked! I added the two newline (\n\n) characters to the *front*, before the long integer (as seen above). I ran the program. Typed in "this is a test" (without quotes). Hit <ctrl-z>. The number 14 appears, and the prog. terminates. Excellent!! I don't know *why* it works, but it does. Anyway, this is a good one for the books.
Thanks R...!!! Thank you all for your input. Now if someone could explain why this needs to be done this way, I would have gained a very valuable lesson.
I can't explain this. All I have seen is that yes, there is a problem with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.
not with windows-95 + borland C 3.0 (it needs a '\n')
I think it is getchar() that want a '\n' for terminate the input in
console (after EOF==<ctrl-z>) elsewhere *the first line in output*
after that is eaten.
"CBFalconer" <cb********@yahoo.com> wrote in message
news:41***************@yahoo.com... It shouldn't make a difference. There is something wrong with your system. What is it, complete with what compiler, etc. you are using.
I'm using win98(*not* se).
I'm using Dev-C++ (version 4.9.9.0) as my compiler.
And as mentioned before, I *do* use the command line at a DOS console rather
than running the program from the IDE.
Thanks,
newby2c
newby2c wrote: "CBFalconer" <cb********@yahoo.com> wrote in message
It shouldn't make a difference. There is something wrong with your system. What is it, complete with what compiler, etc. you are using.
I'm using win98(*not* se). I'm using Dev-C++ (version 4.9.9.0) as my compiler. And as mentioned before, I *do* use the command line at a DOS console rather than running the program from the IDE.
Go to www.delorie.com, use the zip-picker to get enough to compile
and run C programs, and download their installation of gcc. Try
the same sources. That will probably demonstrate that dev-c++ is
wrong. I believe that is also based on gcc.
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
newby2c wrote: "CBFalconer" <cb********@yahoo.com> wrote in message news:41***************@yahoo.com... No, line, enter, ctl-z, enter.
Thanks again. Ran prog. Typed line. Hit <enter> (the caret moved to new line). Hit <ctrl-z>. Prog. terminates. Never had a chance to hit <enter>. This was the program in it's original form (without getchar();). With the getchar(); in place just before the return 0; I type some words, hit <enter>, then hit <ctrl-z>, (prog. does *not* terminate), lastly I hit <enter>. The prog. terminates, but there is still no output.
newby2c
newby2c
It could be a bug in Windows and/or the C runtime.
Change the printf() line to read:
printf("aefore newline\nafter newline %ld\n",nc);
On Windows 98, with MSVC 6.0a (compiler version 12.00.8168) typing
"foobar" newline Ctrl-Z newline, I get:
foobar
after newline 7
Note that everything in the printf() prior to the newline is gone.
On Windows XP:
foobar
^Z
before newline
after newline 7
And the program has not yet exited. I need to press Enter one more time
to get the program to exit.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
"CBFalconer" <cb********@yahoo.com> wrote in message
news:41***************@yahoo.com... Go to www.delorie.com, use the zip-picker to get enough to compile and run C programs, and download their installation of gcc. Try the same sources. That will probably demonstrate that dev-c++ is wrong. I believe that is also based on gcc.
Thanks CB, I just may try that.
newby2c
Kenneth Brody wrote:
.... snip ... It could be a bug in Windows and/or the C runtime.
Change the printf() line to read:
printf("aefore newline\nafter newline %ld\n",nc);
On Windows 98, with MSVC 6.0a (compiler version 12.00.8168) typing "foobar" newline Ctrl-Z newline, I get:
foobar after newline 7
Note that everything in the printf() prior to the newline is gone.
On Windows XP:
foobar ^Z before newline after newline 7
And the program has not yet exited. I need to press Enter one more time to get the program to exit.
It's not W98 FE. Under that, and DJGPP 2.03, gcc 3.3.1:
[1] c:\c\junk>gcc junk.c
[1] c:\c\junk>a
Bloody nonsense
^Z
16
[1] c:\c\junk>type junk.c
#include <stdio.h>
int main(void)
{
long nc;
nc = 0;
while (getchar() != EOF) ++nc;
printf("%ld\n", nc);
return 0;
}
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
"Kenneth Brody" <ke**********@spamcop.net> wrote in message
news:41***************@spamcop.net... It could be a bug in Windows and/or the C runtime.
Change the printf() line to read:
printf("aefore newline\nafter newline %ld\n",nc);
On Windows 98, with MSVC 6.0a (compiler version 12.00.8168) typing "foobar" newline Ctrl-Z newline, I get:
foobar after newline 7
Note that everything in the printf() prior to the newline is gone.
On Windows XP:
foobar ^Z before newline after newline 7
And the program has not yet exited. I need to press Enter one more time to get the program to exit.
I get the same results as you except the program terminates after <ctrl-z>.
newby2c This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mohammed Mazid |
last post by:
Can anyone please help me on how to move to the next and previous
question?
Here is a snippet of my code:
Private Sub cmdNext_Click()
End Sub
Private Sub cmdPrevious_Click()
showrecord
|
by: Stevey |
last post by:
I have the following XML file...
<?xml version="1.0"?>
<animals>
<animal>
<name>Tiger</name>
<questions>
<question index="0">true</question>
<question index="1">true</question>
</questions>
|
by: nospam |
last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types,
so, since it seems to me that Partial Types is still in the design or
development stages at Microsoft, I am going to ask...
|
by: Ekqvist Marko |
last post by:
Hi,
I have one Access database table including questions and answers. Now
I need to give answer id automatically to questionID column. But I
don't know how it is best (fastest) to do?
table...
|
by: glenn |
last post by:
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can
get to their values easily to write to a...
|
by: Rider |
last post by:
Hi, simple(?) question about asp.net configuration..
I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm
first start application the follow message shown.
=========
Server...
|
by: Jeff |
last post by:
In the function below, can size ever be 0 (zero)?
char *clc_strdup(const char * CLC_RESTRICT s)
{
size_t size;
char *p;
clc_assert_not_null(clc_strdup, s);
size = strlen(s) + 1;
|
by: spibou |
last post by:
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?
|
by: Allan Ebdrup |
last post by:
Hi,
I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix
question is a question where you have several options that can all be rated
according to several possible ratings (from...
|
by: Zhang Weiwu |
last post by:
Hello!
I wrote this:
..required-question p:after {
content: "*";
}
Corresponding HTML:
<div class="required-question"><p>Question Text</p><input /></div>
<div...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |