ok im kinda new to C , and i have the c programming language 2nd edition book but when i try to some of the programs from the book in it , it doesnt work!! I mean no errors show but the program isnt running the way is suppose to.

For example, in the 1st chapter where theres 3 parts to characters ,words , lines, and other stuff counting programs, it shows no error while compiling but it doesnt show the output from printf. I have the newest version of dev c++ (i think 4.9.9.2)
but it doesnt work; i tried to the settings and put options like
"support all ansi standard c programs " and "attempt to support some aspect of traditional c programming" and it doesnt change a thing.

ok the problem is not that the program terminates so fast that i cant see anything. I did the getchar() thing at the end. problem is that i see no output like there should be (for example the printf("digits =") ) . I just dont get it! why doesnt it show?! oh yeah and i saved and compiled it as a C source not c++.

09-10-2005

quzah

There's a FAQ on what to do when your program goes away before you like it to. In short, run it from a terminal, or put something at the end to prevent it from exiting until you hit enter or what not:

Code:

while( (c = getchar()) != '\n' );

Also, you can initialize arrays to zero (or anything really, provided you fill in all the elements manually, otherwise any you don't fill in default to zero) at declaration time:

Code:

int array[ SOMESIZE ] = { 0 };

This will set the first array element to zero. All uninitialized elements, provided you have manually initialized at least one, will be zero filled. Note, this does not fill them with the value of the first element, but with zero. Consider:

Code:

int array[ SOMESIZE ] = { 1 };

This doesn't fill them all with 1. It fills the first one with 1, and the rest with zero.

Code:

int array[ SOMESIZE ] = { 0, 1, 2 };

This fills the first with zero, the second with 1, the third with 2, and the remaining with zero.

Quzah.

09-11-2005

Sephiroth

no is not that the program window flashes and quits, the program is suppose to print an output counting the occurences of characters, words, lines, and other stuff but when i enter such characters, i receive no output.

09-11-2005

anonytmouse

The program is fine, Dev-C++ is fine. It is just that this program requires a little unusual input.

1. Type in your input.
2. Press ENTER.
3. Press F6. This is the Windows EOF input key. It must be on a line by itself.
4. Press ENTER.

You can follow these last three steps whenever a program requires an EOF. You can see that this program reads input until it receives an EOF by this line:

Code:

while ((c = getchar()) != EOF)

09-11-2005

Sephiroth

O ya!! it works now . ok i gotta get this straight 1 more time.
so if the program or any program just require anything that has to do with EOF i have to do the F6 thing right? and if it doesnt call eof as an argument of any kind then i wont need to press F6 ever?

09-11-2005

Sephiroth

oh sorry i forgot also one last thing, is there a way to set dev c++ to do the F6 thing automatically whenever eof is called?

09-11-2005

anonytmouse

>> so if the program or any program just require anything that has to do with EOF i have to do the F6 thing right? and if it doesnt call eof as an argument of any kind then i wont need to press F6 ever? <<

Yes. Pretty much. You can also use a file as input. This is called redirection. In this case, the program will receive EOF (which stands for "end of file") at the end of the file. This example shows how to run a program using file.txt as the input.

Code:

>yourprogram < file.txt

>> oh sorry i forgot also one last thing, is there a way to set dev c++ to do the F6 thing automatically whenever eof is called? <<

No. How would it know when to supply the EOF? The EOF allows you to tell the program that you have finished supplying input. If your program only expects a single line of input, it might use the new line character to tell it when the input is complete.