NO

Author Topic: got 2 questions  (Read 3596 times)

draz

  • Guest
got 2 questions
« on: August 19, 2010, 10:45:12 AM »
hi, I'm new to C and Pelles C. I am using the book "The C Programming Language Second Edition" by Brian W. Kernighan & Dennis M. Ritchie. the book did not specify a compiler to use, so by recommendation I downloaded Pelles C. however, I am having some problems.

question #1: why all the extra code?
according to The C Programming Language, the following code SHOULD be sufficient:

#include <stdio.h>

main()

{
printf("Hello, world\n");
}


but it seems that Pelles C requires that I write it like this:


#include <stdio.h>

int main(void)

{
printf("Hello, world\n");
return 0;
}

why does it require more code than my book says it does?

question #2: why won't it run?
I am quite certain that I compiled it as a Console program, but whenever I try to run the program in the command prompt I get messages like this:
"Windows cannot open this file. to open this file, windows needs to know what program you want to use to open it. Windows can go online to look it up automatically, or you can manually select from a list of programs that are installed on your computer."

why won't it run in the command prompt?

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: got 2 questions
« Reply #1 on: August 19, 2010, 06:19:28 PM »
hi, I'm new to C and Pelles C. I am using the book "The C Programming Language Second Edition" by Brian W. Kernighan & Dennis M. Ritchie. the book did not specify a compiler to use, so by recommendation I downloaded Pelles C. however, I am having some problems.

question #1: why all the extra code?
according to The C Programming Language, the following code SHOULD be sufficient:

#include <stdio.h>

main()

{
printf("Hello, world\n");
}


but it seems that Pelles C requires that I write it like this:


#include <stdio.h>

int main(void)

{
printf("Hello, world\n");
return 0;
}

why does it require more code than my book says it does?
Well, because the book is much older than the compiler you're using?

Though 2nd Ed. claims to support ANSI C, certain passages aren't properly updated. It is good programming practice to define the type of functions (here main() ) instead of relying in implicit declarations. And there isn't "That much more code" and in case you come ever back to your own, longer programs after some time, you will start to appreciate being more precise in your programming efforts...
Quote
question #2: why won't it run?
I am quite certain that I compiled it as a Console program, but whenever I try to run the program in the command prompt I get messages like this:
"Windows cannot open this file. to open this file, windows needs to know what program you want to use to open it. Windows can go online to look it up automatically, or you can manually select from a list of programs that are installed on your computer."

why won't it run in the command prompt?
Hard to tell without you telling us more precisely what you did, but it seems you did not tell the Pelles C IDE to produce a standalone .EXE file and you are not starting one either when you get above messages...

In general, you need to be aware that there are subtle differences between the plain "academic" definitions of a book and the compiler and OS specific implementations...

Ralf

draz

  • Guest
Re: got 2 questions
« Reply #2 on: August 20, 2010, 10:07:44 AM »
Ah, I see. I was trying to run the .obj file, not the .exe . lol. thanks for the help.

by the way, does anyone know of any more up to date sources I could switch over to after I finish this book?

Offline Vortex

  • Member
  • *
  • Posts: 862
    • http://www.vortex.masmcode.com
Re: got 2 questions
« Reply #3 on: August 20, 2010, 01:35:40 PM »
theForger's Win32 API Programming Tutorial :

http://www.winprog.org/tutorial
Code it... That's all...

CommonTater

  • Guest
Re: got 2 questions
« Reply #4 on: August 22, 2010, 02:56:02 AM »
Ah, I see. I was trying to run the .obj file, not the .exe . lol. thanks for the help.

by the way, does anyone know of any more up to date sources I could switch over to after I finish this book?

Do some searching for "C in 21 days" and "Introduction to C-99"  There are several good spots to download these tutorials for free.  In my experience they are very close to Pelles C.  I've found them most useful.