Re: Histogram of character frequencies



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>

.



Relevant Pages

  • Re: Is C99 the final C? (some suggestions)
    ... The C standard specifies what is UB and what's not. ... If you have multithreading, they you have to lock and unlock ... > your heap, or use other strategies to make sure one thread isn't in the middle ... Having a different set of condoned operators at each programming ...
    (comp.lang.c)
  • Re: [Lit.] Buffer overruns
    ... > And of course the most direct expression of your, at best, weak support ... Good PLs make good programming easier. ... This is an integrity feature and also ... built-in extension to Standard C. ...
    (sci.crypt)
  • Re: Directory reading
    ... "VIP Star" is a troll who seeks to disrupt the newsgroup, ... by the standard that defines the C programming language. ... support in future revisions of the standard, ...
    (comp.lang.c)
  • Re: Portability: Harmony between PC and microcontroller
    ... int is the natural integer type for the system. ... You are, perhaps unintentionally, paraphrasing the standard in a way ... One of the things that you might not realize is that the C programming ... In the real world, most embedded systems have more complex jobs to do, ...
    (comp.lang.c)
  • Re: Sequence points
    ... They have been in the Standard since the Standard first appeared in 1989, ... you still don't understand sequence points. ... in areas outside of programming. ... programmers are in fact unequal to the demands of assembler language, ...
    (comp.programming)