Re: Histogram of character frequencies
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Sun, 02 Dec 2007 15:15:26 +0530
rajash@xxxxxxxxxxxxxxxxxxxxxxxx wrote:
Johannes Bauer wrote:
rajash@xxxxxxxxxxxxxxxxxxxxxxxx schrieb:
int x[256]; // frequencies
Global.
It's completely acceptable to have variables defined at file scope in
C!
Yes, but in most cases it is not good programming practise.
Indiscriminate use of file and program scope objects were among many of
the reasons a lot of programmers abandoned C in favour of "OO"
languages, which discourage such features even more.
You won't feel the need to encapsulate data for small or even midsize
programs, but believe me, if ever you do go on to work on large
systems, your cavalier programming methodology will be instantly
rejected.
void main()
Illegal.
Why does everyone have this hangup about this? I took a class in C a
while back and my teacher always used void main() { ... }. I can
confirm that it works fine with both MicroSoft compiler and BorLand.
Unfortunately most C programming classes in India are "tool centric",
i.e., they pick an implementation like Turbo C or MSVC and teach
a "dialect" of C that they (the instructors) figured out from their own
half-baked education and their perusal of the documentation for these
compilers. And the documentation usually encourages extensions and
usually fails to provide sufficient warnings about non-standard
constructs.
In the "Real World" C has an internationally accepted Standard, name
ISO/IEC 9899:1999, the latest working draft of which can be downloaded
here:
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>
The actual Standard is available for a cost from ISO and other national
Standards bodies like BIS:
The Standard is the only contract you can trust between you the
programmer and _any_ implementation that claims conformance to it.
Extensions are almost always a much weaker contract between you and a
specific implementation. They need not be supported by any other
conforming implementation (thus linking your code to a particular
compiler) and even the the implementation that does support it today
could drop support tommorrow.
And void main() is not defined as portable by the Standard.
Either you are pretty dumb or you actually do not read ANY of the
answers which are given to you. I vote for number one.
I read the answers but mostly people only comment on trivial things
that aren't even errors! I'll be glad to have substantial comments on
my code.
Your failure to include the relevent headers and your incorrect use of
the feof() functions _are_ real errors. They may happen to work in a
particular run, but nothing whatsoever can be guaranteed about such
broken code.
<snip>
.
- References:
- Histogram of character frequencies
- From: rajash
- Re: Histogram of character frequencies
- From: Johannes Bauer
- Re: Histogram of character frequencies
- From: rajash
- Histogram of character frequencies
- Prev by Date: Re: C Pointers
- Next by Date: Re: hello alls , a newbie here
- Previous by thread: Re: Histogram of character frequencies
- Next by thread: Re: Histogram of character frequencies
- Index(es):
Relevant Pages
|