473,486 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What am I doing wrong??

JS
I have made the following code;
#include <stdio.h>

main(){

int c, i, nwhite, nother;
int ndigit[10];

nwhite = nother = 0;

for (i = 0; i < 10; ++i)
ndigit[i] = 0;

while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
else
if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother;

printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);

printf(", white space = %d, other = %d\n",
nwhite, nother);

}

It compiles ok and I also get an .exe file. But when I doubleclick on the
..exe file from WinXP explorer a black box appears and I can enter som text,
press enter and then nothing happens...the black box does not disappear
before I chose to close it.

I use the Cygwin compiler bcause I need my code to be run on a Linux system.

Hope somone can help

JS
Nov 14 '05 #1
7 1409
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:
I have made the following code;
...
main(){
main should really properly return an int:
int main(void){

.... which will also necessitate adding:
return 0;

just before the closing brace.
It compiles ok and I also get an .exe file. But when I doubleclick on the
.exe file from WinXP explorer a black box appears and I can enter som
text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.


What do you expect? You've got a while loop that doesn't end until it
sees an EOF...

Type in some text, press enter a few times, and then trying sending an EOF
(typically CTRL-D).

Your program should spit out the results as expected.
Michael
Nov 14 '05 #2
JS

"Michael Coyne" <co*****@mtsDOT.net> skrev i en meddelelse
news:pa****************************@mtsDOT.net...
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:
I have made the following code;
...
main(){


main should really properly return an int:
int main(void){

... which will also necessitate adding:
return 0;

just before the closing brace.
It compiles ok and I also get an .exe file. But when I doubleclick on the .exe file from WinXP explorer a black box appears and I can enter som
text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.


What do you expect? You've got a while loop that doesn't end until it
sees an EOF...

Type in some text, press enter a few times, and then trying sending an EOF
(typically CTRL-D).

Your program should spit out the results as expected.


I have tried to enter a few numbers and some text but when I press CTRL-D
the window just closes!
Nov 14 '05 #3
On Mon, 14 Mar 2005 16:15:41 -0600, Michael Coyne said to the parser:
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:
It compiles ok and I also get an .exe file. But when I doubleclick on
the .exe file from WinXP explorer a black box appears and I can enter
som text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.

...
Type in some text, press enter a few times, and then trying sending an EOF
(typically CTRL-D).

Your program should spit out the results as expected.


<OT>
I should also have added that, if you're running this by double-clicking
on it in the Explorer, most likely the minute you hit CTRL-D, the program
will spit out the results and the window will promptly close.

Open up a command prompt, navigate to the proper directory, and then run
the program by typing its name on the command line.
</OT>
Michael
Nov 14 '05 #4
JS

"Michael Coyne" <co*****@mtsDOT.net> skrev i en meddelelse
news:pa****************************@mtsDOT.net...
On Mon, 14 Mar 2005 16:15:41 -0600, Michael Coyne said to the parser:
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:
It compiles ok and I also get an .exe file. But when I doubleclick on
the .exe file from WinXP explorer a black box appears and I can enter
som text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.

...
Type in some text, press enter a few times, and then trying sending an EOF (typically CTRL-D).

Your program should spit out the results as expected.


<OT>
I should also have added that, if you're running this by double-clicking
on it in the Explorer, most likely the minute you hit CTRL-D, the program
will spit out the results and the window will promptly close.

Open up a command prompt, navigate to the proper directory, and then run
the program by typing its name on the command line.
</OT>

I works if I press CTRL+Z instead! Can someone explain the difference
between CTRL+D and CTRL+Z?
Nov 14 '05 #5
Michael Coyne <co*****@mtsDOT.net> writes:
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:

[...]
It compiles ok and I also get an .exe file. But when I doubleclick on the
.exe file from WinXP explorer a black box appears and I can enter som
text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.


What do you expect? You've got a while loop that doesn't end until it
sees an EOF...

Type in some text, press enter a few times, and then trying sending an EOF
(typically CTRL-D).

Your program should spit out the results as expected.


<OT>
If he runs it by double-clicking from a WinXP explorer window, it will
expect control-Z to mark EOF. Once it gets an EOF, the box will close
before he can read the output. He can try running from a command
prompt (MS-DOS window) or from a Cygwin shell (bash, tcsh, whatever).
</OT>

--
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.
Nov 14 '05 #6
JS

"Keith Thompson" <ks***@mib.org> skrev i en meddelelse
news:ln************@nuthaus.mib.org...
Michael Coyne <co*****@mtsDOT.net> writes:
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:

[...]
It compiles ok and I also get an .exe file. But when I doubleclick on the .exe file from WinXP explorer a black box appears and I can enter som
text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.


What do you expect? You've got a while loop that doesn't end until it
sees an EOF...

Type in some text, press enter a few times, and then trying sending an EOF (typically CTRL-D).

Your program should spit out the results as expected.


<OT>
If he runs it by double-clicking from a WinXP explorer window, it will
expect control-Z to mark EOF. Once it gets an EOF, the box will close
before he can read the output. He can try running from a command
prompt (MS-DOS window) or from a Cygwin shell (bash, tcsh, whatever).
</OT>

I found out that I needed to press CTRL+Z, but what is EOF. I know it means
End Of File but is it some specific integer??
Nov 14 '05 #7
JS wrote:
"Keith Thompson" <ks***@mib.org> skrev i en meddelelse
news:ln************@nuthaus.mib.org...
Michael Coyne <co*****@mtsDOT.net> writes:
On Mon, 14 Mar 2005 22:42:23 +0100, JS said to the parser:


[...]
It compiles ok and I also get an .exe file. But when I doubleclick on
the
.exe file from WinXP explorer a black box appears and I can enter som
text, press enter and then nothing happens...the black box does not
disappear before I chose to close it.

What do you expect? You've got a while loop that doesn't end until it
sees an EOF...

Type in some text, press enter a few times, and then trying sending an
EOF
(typically CTRL-D).

Your program should spit out the results as expected.


<OT>
If he runs it by double-clicking from a WinXP explorer window, it will
expect control-Z to mark EOF. Once it gets an EOF, the box will close
before he can read the output. He can try running from a command
prompt (MS-DOS window) or from a Cygwin shell (bash, tcsh, whatever).
</OT>


I found out that I needed to press CTRL+Z, but what is EOF. I know it means
End Of File but is it some specific integer??


EOF is a negative int value defined in <stdio.h>.
Many input functions return EOF if the end-of-file has been
encountered; you can "send" an end-of-file for stdin for example
with CTRL+D on Unix systems and with CTRL+Z on Windows/MS-DOS systems.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
14532
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
121
9896
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
11
2005
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
46
4152
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
4996
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
2
2694
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
16
1964
by: Ajay | last post by:
Hi all, i want to know when i create a class.what all it contains.I know the following things are there by default if i do not declare them by myself.Please tell the other things that are left. ...
8
2053
by: watkinsdev | last post by:
Hi, I have created a mesh class in visual studio 6.0 c++. I can create a device, render objects and can edit the objects by for instancnce selecting a cluster of vertices and processing the...
0
1313
by: shapper | last post by:
Hello, I am creating a class with a control. I compiled the class and used it on an Asp.Net 2.0 web site page. I can see the begin and end tags of my control (<oland </ol>) but somehow the...
10
1773
by: DavidSeck.com | last post by:
Hi, I am working with the Facebook API right now, an I have kind of a problem, but I don't know what I am doing wrong. So I have a few arrays, f.ex.: User albums: array(2) {
0
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7319
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.