Question about the Book I bought...

Started by
12 comments, last by daviangel 19 years, 6 months ago
Quote:Original post by Solidus
I have completed the first chapter and my first program, GOODBYE.C. Im just wondering bout this, when I click on the goodbye.exe it opens cmd and closes in like a 1 sec. Any idea?


Console applications aren't meant to be run by double-clicking on them, but from an existing console. Open a console window (cmd.exe), cd to your executable's directory and type the program's name.

Alternatively, you can create a batch (.BAT) file with the following instructions in it.

yourprogram.exe
pause

And double-click on that instead.

People routinely do add system("pause"); at the end of their program, but I find that this is a half-baked solution : it prevents your program from being easily used from a console (remember, it is a console application), in a pipeline (where the results from one function are passed to another) or in a script (like the batch file I mentioned), since it will unconditionally wait for you to come and press a key - you won't be able to let it go off unattended.

Quote:EDIT: also this was the only book had for programing next to Sams Programing in 24hrs or something which I thought would be a little rushed... Your all making me feel like I just wasted $45 AUS ...


Don't worry about it. I, myself, have bought "OpenGL Programming for Windows 95 and Windows NT" after all. Just make the best out of what the book can teach you, but be ready to reassess what you have learned. At the very least, if you're using gcc (Dev-C++?) do make sure to compile your programs with all warnings enabled (-Wall command-line option, I don't use Dev-C++, so I don't know if there's a checkbox or something for it, though I'd assume so).

Oh, and "Learn XXX in YYY hours/minutes/days" are absolute catastrophes. So you're getting off easy. Also note that some of the people above (me included) did assume you meant C++ for Dummies - I'm less even familiar with the C of the book, though earlier comments about <dos.h> sound about right - the book probably came out when MS-DOS (including Win95) was still a prevalent OS. So keep in mind that things that might have been true ten years ago may be wrong and obsolete today. Computer science evolves quickly.

If you are looking for the canonical C book, check out "The ANSI C Programming Language" by Brian Kernighan and Dennis Ritchie. You might rely on your C for Dummies book for explanations, and on the K&R for correctness.

[Edited by - Fruny on October 9, 2004 4:17:00 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Quote:Original post by Solidus
It doesn't seem that bad...Its C for Dummies: Second Edition btw and its copyright 2004.... so I think its different :)

I have completed the first chapter and my first program, GOODBYE.C. Im just wondering bout this, when I click on the goodbye.exe it opens cmd and closes in like a 1 sec. Any idea?

EDIT: also this was the only book had for programing next to Sams Programing in 24hrs or something which I thought would be a little rushed... Your all making me feel like I just wasted $45 AUS ...


If it gets you up and running with your C programming it shouldn't be a waste. I think that's the key you have to remember. I know a lot of people including myself that have bought books that are highly recommended(c++ primer by lippman or petzold's programming windows) only to let them collect dust because the author put me to sleep or was way over my skills at the time.
p.s. if you skim ahead in your book I'm sure it'll mention using getchar or system pause to see your output(it is a dummies book after all) but then we get back to them bad habits we mentioned to start off with and your better off avoiding.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Oh the author of this book is great, he makes jokes sometimes :) which keeps me reading.

EDIT: also its wrote in simple english, and by me reading this book it givin me a better view on programing ... and ive only read the first chapter
ok well I finally found my "c for dummies" books and they are from 1996 and the links for errata,updates for the books are still valid so you gotta give the author kudos for that!
plus he admits his mistakes and makes an effort to fix them see here:
I use gets() in the book because gets() works. It's not recommended for "real" programs, but for the book it's okay. Just learn to ignore the warning in Linux -- which is legitimate, but okay to overlook while you're learning.


Eventually I'll make available the source code to my own input() function, which handily replaces gets() and uses bounds checking to avoid the problem with gets().


2.1.2 Is gets() really "dangerous"?


gets() is dangerous because it does no bounds checking. That means you can easily type in millions of characters, overflowing your storage buffer and overwriting parts of the program. This exploit has been used for years by the Bad Guys to write worms and viruses, hence the warning.


When you're ready to write programs for others to use, do not use gets()! For learning, however, it's okay.


(I may get in trouble for saying that gets() is "okay for learning," but my opinion is that it's easier to deal with gets() than to fumble over a workaround that causes the student to stumble in the learning process.)


2.1.3 What can I use instead of gets()?


Until I publish my booklet on console programming. I suggest using the fgets() function as a temporary solution and replacement for gets().
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

This topic is closed to new replies.

Advertisement