Re: What's wrong ?
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Thu, 06 Mar 2008 20:26:27 +0530
CBFalconer wrote:
"Daniel.C" wrote:
I just copied this code from my book with no modification :
#include <stdio.h>
/* count characters in input; 1st version */
main()
int main(void)
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
return 0;
}
There is no output, and no completion either. I tried adding a
"printf" at the end of the code, but it doesn't display.
Your book is obsolete and wrong.
The example probably came from K&R2. So you are saying it's obsolete and
wrong. On what basis?
C99 requires the int in the
declaration of main, and the void for parameters is just good
practice. C99 will supply a default return value, but earlier
standards don't. Thus your code is wrong for any version.
They were omitted for brevity, as you well know.
If it doesn't work with the above simple changes, your compiler
system is fouled.
No, his problem is already solved, and it was not a compiletime one.
.
- Follow-Ups:
- Re: What's wrong ?
- From: CBFalconer
- Re: What's wrong ?
- From: Richard
- Re: What's wrong ?
- References:
- What's wrong ?
- From: Daniel.C
- Re: What's wrong ?
- From: CBFalconer
- What's wrong ?
- Prev by Date: Re: What's wrong ?
- Next by Date: Re: alloca
- Previous by thread: Re: What's wrong ?
- Next by thread: Re: What's wrong ?
- Index(es):
Relevant Pages
|