dravid said:
hi i want to know about c.
The C programming language was devised by Dennis Ritchie in the early 1970s.
In 1978, he and Brian Kernighan produced a book called "The C Programming
Language". C had already started to evolve, and the book was at least in
part an attempt to codify the core language.
In 1989, ANSI standardised the language, the standardisation being adopted
internationally (by ISO) in 1990. In anticipation of this, Kernighan and
Ritchie produced a second edition of "The C Programming Language" in 1988,
which took the standardisation changes on board. (Pre-1989 C is now known
as "K&R C".)
The 1989 standardisation was widely desired and widely adopted. (A
subsequent revision to the standard in 1999 has been less popular, and many
people simply ignore it completely.)
C is a very portable and very small language. It is a byword for efficiency.
It's also remarkably easy to write very bad C programs. With care and
experience, however, it is also far easier than people make out to write
/good/ C programs.
Here is a very simple C program, just to give you a taste of what they look
like:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct bigramfreq_
{
char bigram[3];
unsigned long freq;
};
typedef struct bigramfreq_ bigramfreq;
int compbigramfreq(const void *vp1, const void *vp2)
{
const bigramfreq *p1 = vp1;
const bigramfreq *p2 = vp2;
int diff = (p1->freq < p2->freq) - (p1->freq > p2->freq);
if(diff == 0)
{
diff = strcmp(p1->bigram, p2->bigram);
}
return diff;
}
int getoffset(int ch)
{
int offset = -1;
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *p = strchr(alphabet, toupper((unsigned char)ch));
if(p != NULL)
{
offset = p - alphabet;
}
return offset;
}
int main(void)
{
bigramfreq bgf[26*26] = {0};
char buf[3] = {0};
int ch = 0;
int bufpos = 0;
int offsetA = 0;
int offsetB = 0;
unsigned long ubgc = 0;
unsigned long bgc = 0;
unsigned long bg = 0;
int n = 0;
while((ch = getchar()) != EOF)
{
if(bufpos == 0)
{
offsetA = getoffset(ch);
if(offsetA != -1)
{
buf[0] = toupper(ch);
bufpos = 1;
}
}
else
{
offsetB = getoffset(ch);
if(offsetB != -1)
{
buf[1] = toupper(ch);
n = offsetA * 26 + offsetB;
memcpy(bgf[n].bigram, buf, 2);
++bgf[n].freq;
++bgc;
buf[0] = buf[1];
offsetA = offsetB;
}
}
}
qsort(bgf, sizeof bgf / sizeof bgf[0], sizeof bgf[0], compbigramfreq);
for(bg = 0; bg < sizeof bgf / sizeof bgf[0]; bg++)
{
if(bgf[bg].freq > 0)
{
++ubgc;
printf(" { \"%s\", %6lu }, \n", bgf[bg].bigram, bgf[bg].freq);
}
}
printf("Total bigrams: %lu; Unique bigrams found in this corpus: %lu.\n",
bgc, ubgc);
return 0;
}
The comp.lang.c FAQ list can be found online at
http://c-faq.com - the book
version (see Recommended Books) contains considerably more material, but of
course the online version is free.
There are plenty of C tutorials on the Web. Most seem to be written either
by inexperienced C programmers who wish to pass on their lack of experience
to others (such tutorials should be avoided completely), or by people who
make the basic assumption that "obviously my readers will be using the same
platform as me". This latter category is harder to dismiss, since some
people aren't really fussed about learning the C language per se; they only
care about using C on one particular platform. For such people, if they can
find a good tutorial that devotes itself to their platform, that's great.
But when I learn about a new tutorial site, I'm afraid I can't always
afford the time to check the site out in detail, so I generally wind up
looking for obvious errors (of a kind that a C expert would not make), or
platform dependent advice. If I find either, I deduce that the tutorial,
for whatever reason, is not suitable for teaching the C language itself,
and read no further.
It's quite difficult to pass muster when the standard is so strict, but two
sites do meet my criteria of correctness and portability.
* Steve Summit's excellent, and rather gentle, tutorial can be found at
http://www.eskimo.com/~scs/cclass/; the serious C student will benefit most
from this tutorial if he or she has a copy of "The C Programming Language",
2nd edition, by Kernighan and Ritchie (see Books, below).
* Tom Torfs takes a rather more austere approach; this doesn't suit
everybody, but many people have found it extremely helpful. His tutorial
can be found at
http://cprog.tomsweb.net/cintro.html
The two most important ways of getting help with C interactively on the
Internet are Usenet and IRC. (I mean "interactive" in the sense of being
able to ask a question in your own words and getting an answer from a real
live human.) If you're learning C and don't have a teacher to guide you
through the language, IRC and Usenet can be handy places to get some quick
advice. Beware, though: neither is a substitute for a knowledgeable C
teacher (alas, these are rare), or a really good book on C.
Usenet is a batch-driven environment, in which you subscribe to a news
service (this is normally provided freely by ISPs as part of your Internet
"package"), and can post articles to that service. The best Usenet
"newsgroups" on which to get C help are comp.lang.c (fast and furious) and
comp.lang.c.moderated (slower, but considerably less furious!). When using
Usenet, be patient. It takes time (sometimes as much as a day or two) for
your article to be propagated on news servers around the world. Also,
please remember that nobody is obliged to help you. In general, you are
more likely to get help if the answer to your question is (a) not in the
FAQ, (b) not one of those that crops up every other day but doesn't seem to
have made it into the FAQ, and (c) actually about the C language, rather
than some particular platform.
Please read the comp.lang.c welcome notice before diving too quickly into
the newsgroup. This notice, as well as being on the Web, is posted in the
newsgroup on a regular basis. Thank you.
IRC (Internet Relay Chat) is more immediate. If you are lucky, you can get a
good answer to your C question within a few seconds of asking it. A
considerable amount of C expertise lurks within IRC, although perhaps not
as much as can be found in comp.lang.c; unfortunately, it is in the nature
of a real-time forum that the quality of advice you get very much depends
on who is around (and awake!) at the time. Also, IRC channels are generally
far less formal than the Usenet "equivalents", and can sometimes get
clogged up with useless discussions of subjects unrelated to C (mind you,
that happens on Usenet, too, although perhaps not to such a great extent).
There are a great many books on C. Many are of low quality. Some are rather
better. I haven't bothered mentioning the low quality books here.
If you have never programmed before, and would like to learn C as your first
programming language, I suggest either of the following two books:
C Programming: A Modern Approach, K.N.King, W.W.Norton & Company, 1996. ISBN
0-393-96945-2
C: How to Program, 2nd Ed. Deitel, H.M. & Deitel, P.J. Prentice Hall, 1994.
ISBN: 0-13-226119-7 (Actually, they're now up to their 5th edition, but I
don't have the ISBN handy.)
If you are already an experienced programmer, but just haven't yet learned
C, you will appreciate the briefer approach of Brian Kernighan (silent 'g',
by the way), and Dennis Ritchie. Kernighan is the 'K' in AWK, and Dennis
Ritchie wrote the C language itself. The book is very short (272 pages
including the index), but its information density is colossal. This book
teaches you more about C than many books four times the size:
The C Programming Language, 2nd Ed. Kernighan & Ritchie. Prentice Hall,
1988. ISBN 0-13-110362-8 (paperback), or 0-13-110370-9 (hardback).
It should be remembered, when selecting a C compiler, that many C compilers
also provide a C++ feature. Thus, you may well find yourself downloading a
"C++ compiler", and be wondering whether it will actually support the C
language. The answer is: "probably". I can certainly assure you that
Borland C++, Microsoft C++ ("DevStudio"), and gcc are all very good C
compilers. Just remember, when using a compiler that can handle both
languages, to tell it (as firmly as you think necessary) that you are using
C, not C++. Generally, if you're using a typical desktop PC operating
system and compiler, simply using a .c extension on your filename is
sufficient to convince your compiler that you really do want C, not C++.
* King of the free compilers, gcc is not just free, but also open
source. And it's an extremely good compiler, used by hobbyists and
professionals the world over. (I've used gcc on eight different client
sites over the last six years or so.) This is my compiler of choice.
http://gcc.gnu.org
* The command line version of the superb C compiler Borland 5.5 is,
believe it or not, free of charge.
http://www.borland.com/bcppbuilder/freecompiler/
* Also from Borland (this time from their "museum" site), is the
not-quite-conforming (but close enough) Turbo C 2.01. A complete C compiler
in about one Megabyte. And yes, lots of commercial programs were written
with this program, in its day. And yes, it works just as well as ever it
did back in 1989. (Except that it's a bit quicker nowadays.) Works fine on
ancient kit (no surprise there), and I still use it occasionally on modern
boxes, without problems.
http://community.borland.com/article/0,1410,20841,00.html
* D J Delorie's gcc port for MS-DOS is quite a nice compiler, although I
had a certain (small) amount of hassle installing it. 80386 or better
required.
http://www.delorie.com/djgpp/
* MinGW (Windows port of gcc)
http://www.mingw.org
* The Digital Mars C compiler
http://www.digitalmars.com
* lcc, an ANSI C compiler.
http://www.cs.princeton.edu/software/lcc/
* LCC-win32
http://www.cs.virginia.edu/~lccwin32
* Pacific C
http://www.hitech.com.au/products/pacific.html
* Microsoft C is now available for free download, if you don't mind
using the command line.
http://msdn.microsoft.com/visualc/vctoolkit2003/
The following sites are generally useful:
http://www.lysator.liu.se/c/ - The Lysator C Page
http://www.dinkumware.com/ - DinkumWare
http://www.gnu.org - GNU
http://vision.eng.shu.ac.uk/bala/c/c/optimisation/1/optimization.html -
Mikey Lee's guide to optimising C programs
http://www-ccs.ucsd.edu/c/ - An excellent C reference guide written by no
less than Brodie and Plauger
http://www.ericgiguere.com/articles/reading-c-declarations.html - Eric
Giguere's Guide to Reading C Declarations
http://pw2.netcom.com/~tjensen/ptr/cpoint.htm - A Pointer Tutorial
http://www.function-pointer.org - Function Pointer Tutorial
http://www.oakroadsystems.com/tech/c-predef.htm - A list of identifiers to
avoid in your C programs
http://herd.plethora.net/~seebs/c/c_tcr.html - C - The Complete Nonsense (a
Schildt critique)
http://herd.plethora.net/~seebs/faqs/c-iaq.html - C - Infrequently Asked
Questions
http://www.ioccc.org - The International Obfuscated C Coding Competition
http://cm.bell-labs.com/cm/cs/cbook/index.html - "The C Programming
Language" Home Page
http://www.cs.bell-labs.com/who/dmr/ - Dennis Ritchie's Home Page
http://cm.bell-labs.com/cm/cs/who/bwk/ - Brian Kernighan's Home Page
http://www.davros.org/ - Clive Feather's Home Page
http://www.iso-9899.info/ - The Freenode #c IRC channel Home Page
http://www.iedu.com/ - Morris Dovey's Home Page
http://home.att.net/~jackklein/ - Jack Klein's Home Page
http://www.adtinfo.org - Ben Pfaff's Home Page