Trying to get started in C [closed] - c

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Does anyone know any good resources with tasks or problems to get practice in things that are "new" in C from the point of view of someone with experience in high-level languages like C# and PHP? All I can seem to find are more "challenges" than problems for practice.
Thanks.

K & R. [Kernighan & Ritchie]
http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628/ref=pd_bbs_1?ie=UTF8&s=books&qid=1240539543&sr=8-1

You could try Thinking in C by Bruce Eckel.
It is completely free of charge, and is available for download from his website.

As others have said, read K&R.
Pay special attention to pointers, structs, unions, bit fields, typedefs, and the C preprocessor. Pointers and pointer arithmetic are very important.
Read the C preprocessor manual.
Learn to write makefiles. Read the manual for your version of make.

K&R is outdated.
I prefer C Primer Plus 5th Ed by Stephen Prata
ISBN: 0-672-32696-5
It covers C99.

This supposed to be C bible.

Problem Solving and Program Design in C
by
Jeri R. Hanly, Elliot B. Koffmon and Frank L. Friedman

Check out The Standard C Library by P. J. Plauger, from 1991. It alternates quotes from the standard (C89, I believe) with discussion of how the library functions were intended to be used, along with a fully described implementation of the complete C standard library. Source code is included as well.
Yes, the book hasn't been updated for the latest standard, but it still has a lot of value from explaining at least some of the rationale behind some of the oddities of the standard library. Incidentally, Plauger was on the standards committee.
Plauger wrote a number of the classic books on both C and early Unix. Track down and read the oldest for a taste of pre-C history...

Given your previous (C#) programming experience I guess you don't need a book that teaches how to program but the intricacies and subtleties of C. I'd recommend the following:
Prentice Hall - The ANSI C Programming Language 2nd ed. by Brian W. Kernighan and Dennis M. Ritchie. For basic questions.
Prentice Hall - Expert C Programming. Deep C Secrets.
ISO - C 99 Standard - final. Very useful for many doubts and questions

A source of problems to solve that have known answers is Project Euler.
It isn't itself C specific since there is a decidedly mathematical orientation to the problems as presented. However, making an honest attempt to solve a significant number of them would require a growing proficiency with structures, pointers, the standard library, and thinking about things in ways that work well in C.
Another resource that often seems to be overlooked is that MIT has been putting a large percentage of their curriculum online. Their EE/CS department is no exception.
The class Introduction to Algorithms might be one suitable choice. The textbook is Introduction to Algorithms, Second Edition, by Cormen, Leiserson, Rivest, and Stein which is reasonably well written as text books go. I didn't exhaustively search the course list, so I'm sure there are other gems in there as well.

Related

Tutorials for Code Obfuscation in C [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am fascinated by the way people obfuscate their code (mostly, C) (examples here : http://ioccc.org/) and would like to learn the various techniques for the same. I have been told of a book, "Obfuscated C and other Mysteries", but I am not able to get that book.
Are there any tutorials or books that give hints on this topic?
Thank you.
The best you can do is read the comments of the author of the programs on IOCCC. They describe how they manage to obfuscate their code. Here are a few pointers:
Short and meaningless identifiers
Because a=aaa*aa; will always be more obfuscated than result = value * factor;
In order to have short identifiers, obfuscators tend to even #define many things.
Reversed array indexing
You just have to remember that var[3] and 3[var] are equivalent.
Digraphs and trigraphs
if(a< <:b+aa??))??<f();%>
should be less readable than:
if (a < (b+aa)) { f(); }
Look-alike characters
Sometimes, it's hard to tell appart l, 1 and I or o, 0 and O. For example, if you write 10l, I bet everyone will read 101 instead.
Coding style guidelines
Generally speaking, just try to find good coding guidelines and to try to violate them all. Those documents that you could find anywhere on the web could help you more than most things and would allow you not to buy anything.
Here are some links:
How to write unmaintainable code.
Morwenn's answer nicely covers obfuscation of syntax. But there is another level, and that is semantic obfuscation. Consider that the oft-mentioned Turing Machine has the same computational power as any other programming language (ignoring considerations of input and output). In fact all of the various models of computation have sibling models with equivalent power.
For example, a string char s[N] can be considered a mapping from indices to characters, so any string can be represented instead by a function which always delivers the appropriate character when called with a specified index char f(int i). Now read this. Crazy, right?

Is "K&R C" still applicable [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I relearning C; it's been years and whilst familiar the nuances are lost in time.
I originally learned C from K&R. However, I now see many people levelling criticism at K&R.
A chief example is http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html#x61-27200055
Top reasons seem to be that it's code style is overly terse, practises aren't applicable in larger programs and lead to memory leaks or are subject to attack in shared network accessible systems.
Do people feel these criticisms are fair? Do they matter to somebody learning C? If so, could people recommend a "modern" C book, preferably available for Kindle?
As long as you're talking about the 2nd Edition, K&R is still very relevant.
In fact, I would say it's still the very best single book on C, both for learning, and for reference.
That said, you should also get a copy of Harbison & Steele's "C: A Reference Manual". It's the best current reference on C, and the Fifth Edition covers C99, which you should use if you can.
Also, once you've got a bit of C behind you, I'd strongly recommend reading "Expert C Programming", by Peter van der Linden.
It is still relevant and still very useful with regards to learning the language. Learning the language doesn't require you to implement new practices or styles that assist in code readability, etc.
For example, the idea of self documenting code is that you use verbose variable and function names to help explain the purpose of a function or a variable. K&R is clearly opposed to this. That doesn't mean you can't learn the C language from K&R, it just means that your style will need to be adjusted/updated based on whatever naming convention you decide upon in the future.
I cannot recommend "Expert C Programming" enough (as stated by gregj).

Compiler C to Brainfuck (for harassing a professor)? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
A professor of mine has said he'll accept homework assignments in any language we'd care to use. I'm on good enough terms that I'd like to mess with him a bit and submit a valid homework assignment using brainfuck, whitespace, or some equally "useful" language.
I have the C-sources for a few simple numerical analysis routines as well as the compiled output and the assembly files they generate.
Does anyone know of a decompiler (or a C->brainfuck translator) that could give me something akin to the "brainfuck source code"?
Just use APL or J.
Unlike BF, they were actually designed to serve a "useful" (and not a "useful as in BF" sense) purpose - and yet can easily make Perl code-golf entries look like novels. (The dedication and mental training to enjoy these languages is currently more than my skill/effort levels.)
If the goal is using a purely esoteric language, I have always enjoyed the look of Piet programs. It looks prettier and is actually able to solve common CS homework problems. Following the links will reveal "Piet assemblers" and other tools. Win.
Happy coding.
For what it's worth, I just wrote a very simple Brainfuck Assembler (inspired by this SO post actually), which assembles readable source code (not C, just something simple and nameless) to BrainFuck. The source-code and compilation/usage instructions can be found here: BrainFuck Assembler.
Edit: The project has recently been updated under a new name: BrainFix.
Edit 2: I redid the entire project. The new and improved version has quite a lot of features and is available on Github.
A quick Google search brings up the (a?) Brainfuck site, which links to an archive with "all things Brainfuck". I doubt there's a C->brainfuck translator anywhere, I wouldn't think anyone would invest that much time.

Algorithm and data structure implementations for C programmers [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Are there any open source C libraries with common data structures?
What is the best source of algorithm and data structure implementations for C programmers? Links to an open source library or a book will do. (Please don't point to Sedgewick, as I already have his book).
Though I have not used GDSL ( Generic Data Structures Library ) I think it's worth considering as it implements many frequently used data structures.
The Algorithm Design Manual by Steven Skiena
(source: alberton.info)
Another C library worth checking out, especially because it hasn't been mentioned in answers to this question and also the other duplicate questions:
the C Algorithms Library, it can be found at http://c-algorithms.sourceforge.net/ and is covered by a BSD-style license, i.e. it can be freely used in any project. I've used it myself in several smaller programs without encountering any problems.
Art of Computer Programming, Volume 1: Fundamental Algorithms (3rd Edition)
http://en.wikipedia.org/wiki/The_Art_of_Computer_Programming

C Pointers - Good Tutorials [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
What are the barriers to understanding pointers and what can be done to overcome them?
Was just wondering if anyone could "point me" to a good tutorial on pointers
Would be very greatful
Thanks
The best start is Kernighan and Ritchie book of "Programming in C".
There is always Pointer Fun with Binky, produced by Stanford.
Well, http://pweb.netcom.com/~tjensen/ptr/cpoint.htm seems quite reasonable.
I like C for smarties a lot. It deals with many of the issues people face with pointers, is written by someone who knows C very well, and to paraphrase Einstein, doesn't simplify things more than they need to be. In particular, you should read "Are pointers numbers?", and "More on arrays and pointers" from the website.
Also, see comp.lang.c FAQ, sections 4, 5, 6, and 7.
While not related only to pointers, Defensive Programming is something that should definitely read up on and practice.It greatly reduces the number of mistakes that a programmer can mak
Here's a couple of nice links:
Dr Dobbs - http://www.drdobbs.com/cpp/184401915
Defensive C Programming - http://geofftop.com/Defensive_C_Programming.html
Read The C Programming Language by Brian Kernighan and Dennis Ritchie; it is excellent.

Resources