diff --git a/Makefile b/Makefile index 75170bf..99a0522 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ JUNK_FILES=$(FINAL).* *.aux *.log styles/*.aux SOURCE=book -WEBSITE=$(USER)@mongrel2.org:/var/www/mongrel2.org/static/ -FINAL=book-final +WEBSITE=$(USER)@learncodethehardway.org:/var/www/learncodethehardway.org +FINAL=LearnCTheHardWay-preview book: dexy cp Makefile output/ cp pastie.sty output/ - ${MAKE} -C output clean book-final.pdf + ${MAKE} -C output clean $(FINAL).pdf rm -rf output/*.dvi output/*.pdf ${MAKE} -C output $(FINAL).pdf @@ -17,9 +17,9 @@ $(FINAL).dvi: cp $(SOURCE).tex $(FINAL).tex latex -halt-on-error $(FINAL).tex -html: - htlatex $(FINAL).tex - tidy -quiet -ashtml -omit -ic -m $(FINAL).html || true +html: + cd output && htlatex $(FINAL).tex + cd output && tidy -quiet -ashtml -omit -ic -m $(FINAL).html || true $(FINAL).pdf: $(FINAL).dvi dvipdf $(FINAL).dvi @@ -34,8 +34,8 @@ clean: release: clean $(FINAL).pdf draft $(FINAL).pdf sync -sync: - rsync -vz $(FINAL).pdf $(WEBSITE)/book/LearnCTheHardWay-preview.pdf - rsync -vz $(FINAL).html $(WEBSITE)/book/LearnCTheHardWay.html - rsync -vz $(FINAL).css $(FINAL)[0-9]*.html $(WEBSITE)/book/ +sync: book html + rsync -vz output/$(FINAL).pdf $(WEBSITE)/$(FINAL).pdf + rsync -vz output/$(FINAL).html $(WEBSITE)/index.html + rsync -vz output/$(FINAL).css $(WEBSITE)/ diff --git a/book.tex b/book.tex index 74459bf..ac1dec5 100644 --- a/book.tex +++ b/book.tex @@ -21,6 +21,61 @@ \mainmatter \include{introduction} +\include{ex0} +\include{ex1} +\include{ex2} +\include{ex3} +\include{ex4} +\include{ex5} +\include{ex6} +\include{ex7} +\include{ex8} +\include{ex9} +\include{ex10} +\include{ex11} +\include{ex12} +\include{ex13} +\include{ex14} +\include{ex15} +\include{ex16} +\include{ex17} +\include{ex18} +\include{ex19} +\include{ex20} +\include{ex21} +\include{ex22} +\include{ex23} +\include{ex24} +\include{ex25} +\include{ex26} +\include{ex27} +\include{ex28} +\include{ex29} +\include{ex30} +\include{ex31} +\include{ex32} +\include{ex33} +\include{ex34} +\include{ex35} +\include{ex36} +\include{ex37} +\include{ex38} +\include{ex39} +\include{ex40} +\include{ex41} +\include{ex42} +\include{ex43} +\include{ex44} +\include{ex45} +\include{ex46} +\include{ex47} +\include{ex48} +\include{ex49} +\include{ex50} +\include{ex51} +\include{ex52} +\include{next} +\include{improving} \appendix diff --git a/code/ex1.c b/code/ex1.c index 5f3655d..a179578 100644 --- a/code/ex1.c +++ b/code/ex1.c @@ -1,4 +1,4 @@ -void main() +int main() { puts("Hello world."); } diff --git a/code/ex3.c b/code/ex3.c new file mode 100644 index 0000000..5547f63 --- /dev/null +++ b/code/ex3.c @@ -0,0 +1,8 @@ +#include + +int main() +{ + int age = 10; + printf("I am %d years old\n", age); +} + diff --git a/ex0.tex b/ex0.tex new file mode 100644 index 0000000..9ed86b6 --- /dev/null +++ b/ex0.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 0: The Setup} + +This is how you setup your computer to work through this book. diff --git a/ex1.tex b/ex1.tex new file mode 100644 index 0000000..25f342b --- /dev/null +++ b/ex1.tex @@ -0,0 +1,21 @@ +\chapter{Exercise 1: Dust Off That Compiler} + +Here is a simple first program you can make in C: + +\begin{code}{ex1.c} +<< d['code/ex1.c|pyg|l'] >> +\end{code} + +You can put this into a \file{ex1.c} then type: + +\begin{code}{Building ex1} +\begin{Verbatim} +make ex1 +./ex1 +\end{Verbatim} +\end{code} + +Try it and let me know if it worked. If you type this \verb|make ex1.c| then +you're doing it wrong and need to pay attention to what I typed. C does not +treat kindly those who lack attention to detail. + diff --git a/ex10.tex b/ex10.tex new file mode 100644 index 0000000..7628241 --- /dev/null +++ b/ex10.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 10} + + diff --git a/ex11.tex b/ex11.tex new file mode 100644 index 0000000..e34b9ff --- /dev/null +++ b/ex11.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 11} + + diff --git a/ex12.tex b/ex12.tex new file mode 100644 index 0000000..611e87f --- /dev/null +++ b/ex12.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 12} + + diff --git a/ex13.tex b/ex13.tex new file mode 100644 index 0000000..67b54a6 --- /dev/null +++ b/ex13.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 13} + + diff --git a/ex14.tex b/ex14.tex new file mode 100644 index 0000000..7521c4f --- /dev/null +++ b/ex14.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 14} + + diff --git a/ex15.tex b/ex15.tex new file mode 100644 index 0000000..38f6a15 --- /dev/null +++ b/ex15.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 15} + + diff --git a/ex16.tex b/ex16.tex new file mode 100644 index 0000000..b43d11b --- /dev/null +++ b/ex16.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 16} + + diff --git a/ex17.tex b/ex17.tex new file mode 100644 index 0000000..7cddc86 --- /dev/null +++ b/ex17.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 17} + + diff --git a/ex18.tex b/ex18.tex new file mode 100644 index 0000000..ad57ba2 --- /dev/null +++ b/ex18.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 18} + + diff --git a/ex19.tex b/ex19.tex new file mode 100644 index 0000000..fed4fb9 --- /dev/null +++ b/ex19.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 19} + + diff --git a/ex2.tex b/ex2.tex new file mode 100644 index 0000000..37a1762 --- /dev/null +++ b/ex2.tex @@ -0,0 +1,25 @@ +\chapter{Exercise 2: Make Is Your Python Now} + +In \href{http://learnpythonthehardway.org}{Python} you ran programs by just +typing \verb|python| and the code you wanted to run. The Python interpreter +would just run them, and import any other libraries and things you needed +on the fly as it ran. C is a different beast completely where you have to +\emph{compile} your source files and manually stitch them together into +a binary that can run on its own. Doing this manually is a pain, and in +the last exercise you just ran \file{make} to do it. + +In this exercise, you're going to get a crash course in GNU make, and you'll +be learning to use it as you learn C. Make will for the rest of this book, +be your Python. It will build your code, and run your tests, and set things +up and do all the stuff for you that Python normally does. + +The difference is, I'm going to show you smarter Makefile wizardry, where you +don't have to specify every stupid little thing about your C program to get +it to build. I won't do that in this exercise, but after you've been using +"baby make" for a while, I'll show you "master make". + +... explain basic usage of make to just build single files ... + +... go into a simple makefile ... + +... show how to run the simple makefile ... diff --git a/ex20.tex b/ex20.tex new file mode 100644 index 0000000..eb43714 --- /dev/null +++ b/ex20.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 20} + + diff --git a/ex21.tex b/ex21.tex new file mode 100644 index 0000000..10d1a3f --- /dev/null +++ b/ex21.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 21} + + diff --git a/ex22.tex b/ex22.tex new file mode 100644 index 0000000..5d22f16 --- /dev/null +++ b/ex22.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 22} + + diff --git a/ex23.tex b/ex23.tex new file mode 100644 index 0000000..5fdfabb --- /dev/null +++ b/ex23.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 23} + + diff --git a/ex24.tex b/ex24.tex new file mode 100644 index 0000000..8f0c98b --- /dev/null +++ b/ex24.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 24} + + diff --git a/ex25.tex b/ex25.tex new file mode 100644 index 0000000..915aa86 --- /dev/null +++ b/ex25.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 25} + + diff --git a/ex26.tex b/ex26.tex new file mode 100644 index 0000000..58bcd16 --- /dev/null +++ b/ex26.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 26} + + diff --git a/ex27.tex b/ex27.tex new file mode 100644 index 0000000..3174ee9 --- /dev/null +++ b/ex27.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 27} + + diff --git a/ex28.tex b/ex28.tex new file mode 100644 index 0000000..b272363 --- /dev/null +++ b/ex28.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 28} + + diff --git a/ex29.tex b/ex29.tex new file mode 100644 index 0000000..57de747 --- /dev/null +++ b/ex29.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 29} + + diff --git a/ex3.tex b/ex3.tex new file mode 100644 index 0000000..75dc9e5 --- /dev/null +++ b/ex3.tex @@ -0,0 +1,18 @@ +\chapter{Exercise 3: Formatted Printing} + +Many programming languages use the C way of formatting output, so let's try it: + +\begin{code}{ex3.c} +<< d['code/ex3.c|pyg|l'] >> +\end{code} + +Once you have that, do the usual \shell{make ex3} to build it and run it. + +This exercise has a whole lot going on in a small amount of code. First you're +including another "header file" called \file{stdio.h}, then you're using a variable +named \ident{age} and setting it to 10. Then you're printing it out using the +function \ident{printf} and a format string similar to what you would use +in Python. + +... explain this ... + diff --git a/ex30.tex b/ex30.tex new file mode 100644 index 0000000..c22cb79 --- /dev/null +++ b/ex30.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 30} + + diff --git a/ex31.tex b/ex31.tex new file mode 100644 index 0000000..75c7cbb --- /dev/null +++ b/ex31.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 31} + + diff --git a/ex32.tex b/ex32.tex new file mode 100644 index 0000000..20fe052 --- /dev/null +++ b/ex32.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 32} + + diff --git a/ex33.tex b/ex33.tex new file mode 100644 index 0000000..a10392c --- /dev/null +++ b/ex33.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 33} + + diff --git a/ex34.tex b/ex34.tex new file mode 100644 index 0000000..e5ed168 --- /dev/null +++ b/ex34.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 34} + + diff --git a/ex35.tex b/ex35.tex new file mode 100644 index 0000000..8b66a32 --- /dev/null +++ b/ex35.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 35} + + diff --git a/ex36.tex b/ex36.tex new file mode 100644 index 0000000..d0a88c9 --- /dev/null +++ b/ex36.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 36} + + diff --git a/ex37.tex b/ex37.tex new file mode 100644 index 0000000..b9f844c --- /dev/null +++ b/ex37.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 37} + + diff --git a/ex38.tex b/ex38.tex new file mode 100644 index 0000000..ce56fa2 --- /dev/null +++ b/ex38.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 38} + + diff --git a/ex39.tex b/ex39.tex new file mode 100644 index 0000000..7bbe5c8 --- /dev/null +++ b/ex39.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 39} + + diff --git a/ex4.tex b/ex4.tex new file mode 100644 index 0000000..1b955fe --- /dev/null +++ b/ex4.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 4} + + diff --git a/ex40.tex b/ex40.tex new file mode 100644 index 0000000..d3eca83 --- /dev/null +++ b/ex40.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 40} + + diff --git a/ex41.tex b/ex41.tex new file mode 100644 index 0000000..7b82958 --- /dev/null +++ b/ex41.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 41} + + diff --git a/ex42.tex b/ex42.tex new file mode 100644 index 0000000..826b0c9 --- /dev/null +++ b/ex42.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 42} + + diff --git a/ex43.tex b/ex43.tex new file mode 100644 index 0000000..39a6bfa --- /dev/null +++ b/ex43.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 43} + + diff --git a/ex44.tex b/ex44.tex new file mode 100644 index 0000000..a49f5d1 --- /dev/null +++ b/ex44.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 44} + + diff --git a/ex45.tex b/ex45.tex new file mode 100644 index 0000000..14c7a6e --- /dev/null +++ b/ex45.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 45} + + diff --git a/ex46.tex b/ex46.tex new file mode 100644 index 0000000..6e9c75b --- /dev/null +++ b/ex46.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 46} + + diff --git a/ex47.tex b/ex47.tex new file mode 100644 index 0000000..abd05d0 --- /dev/null +++ b/ex47.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 47} + + diff --git a/ex48.tex b/ex48.tex new file mode 100644 index 0000000..76c8509 --- /dev/null +++ b/ex48.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 48} + + diff --git a/ex49.tex b/ex49.tex new file mode 100644 index 0000000..d22da0c --- /dev/null +++ b/ex49.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 49} + + diff --git a/ex5.tex b/ex5.tex new file mode 100644 index 0000000..94b9787 --- /dev/null +++ b/ex5.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 5} + + diff --git a/ex50.tex b/ex50.tex new file mode 100644 index 0000000..bb99989 --- /dev/null +++ b/ex50.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 50} + + diff --git a/ex51.tex b/ex51.tex new file mode 100644 index 0000000..38ea398 --- /dev/null +++ b/ex51.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 51} + + diff --git a/ex52.tex b/ex52.tex new file mode 100644 index 0000000..133a544 --- /dev/null +++ b/ex52.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 52} + + diff --git a/ex6.tex b/ex6.tex new file mode 100644 index 0000000..56e61af --- /dev/null +++ b/ex6.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 6} + + diff --git a/ex7.tex b/ex7.tex new file mode 100644 index 0000000..64689be --- /dev/null +++ b/ex7.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 7} + + diff --git a/ex8.tex b/ex8.tex new file mode 100644 index 0000000..a10d505 --- /dev/null +++ b/ex8.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 8} + + diff --git a/ex9.tex b/ex9.tex new file mode 100644 index 0000000..95211f3 --- /dev/null +++ b/ex9.tex @@ -0,0 +1,3 @@ +\chapter{Exercise 9} + + diff --git a/improving.tex b/improving.tex new file mode 100644 index 0000000..a7e4aec --- /dev/null +++ b/improving.tex @@ -0,0 +1,3 @@ +\chapter{Thoughts On Improving C} + +After decades of using C, I have some ideas for improving it. diff --git a/introduction.tex b/introduction.tex index c1a59c2..84065d1 100644 --- a/introduction.tex +++ b/introduction.tex @@ -1,22 +1,31 @@ -\chapter{Introduction} - -The introduction to "Learn C The Hard Way". - -Here is a simple first program you can make in C: - -\begin{code}{Simple C Program} -<< d['code/ex1.c|pyg|l'] >> -\end{code} - -You can put this into a \file{ex1.c} then type: - -\begin{code}{Building ex1} -\begin{Verbatim} -make ex1 -./ex1 -\end{Verbatim} -\end{code} - -Try it and let me know if it worked. +\chapter{Introduction: The Cartesian Dream Of C} + +\begin{quotation} + +Whatever I have up till now accepted as most true and assured I have gotten +either from the senses or through the senses. But from time to time I have +found that the senses deceive, and it is prudent never to trust completely +those who have deceived us even once. + + \attrib{Rene Descartes, Meditations On First Philosophy} +\end{quotation} + +If there ever were a quote that described programming with C, it would be this. +To many programmers, this makes C scary and evil. It is the Devil, Satan, the +trickster Loki come to destroy your productivity with his seductive talk of +pointers and direct access to the machine. Then, once this computational +Lucifer has you hooked, he destroys your world with the evil "segfault" and +laughs as he reveals the trickery in your bargain with him. + +But, C is not to blame for this state of affairs. No my friends, your computer +and the Operating System controlling it are the real tricksters. They conspire +to hide their true inner workings from you so that you can never really know +what is going on. The C programming language's only failing is giving you +access to what is really there, and telling you the cold hard raw truth. C +gives you the red pill. C pulls the curtain back to show you the wizard. +\emph{C is truth.} + +Why use C then if it's so dangerous? Because C gives you power over the false +reality of abstraction and liberates you from stupidity. diff --git a/preamble.tex b/preamble.tex index a472748..aa0b501 100644 --- a/preamble.tex +++ b/preamble.tex @@ -3,7 +3,7 @@ \usepackage{pastie} %\usepackage{palatino} \usepackage[ - pdftitle={Learn C The Hard Way: A Clear and Direct Introduction To Programming In C}, + pdftitle={Learn C The Hard Way: A Clear \& Direct Guide To Modern C Programming}, pdfauthor={Zed A. Shaw}, pdfsubject={An introduction to C programming for people who know one other language.}, pdfkeywords={C, Programming}, @@ -14,12 +14,13 @@ ]{hyperref} \usepackage{float} \usepackage{fancybox} -\usepackage{savetrees} +%\usepackage{savetrees} \usepackage{fancyvrb} \usepackage{color} \usepackage{parskip} \usepackage{textcomp} \usepackage{listings} +\usepackage{attrib} \parskip 7.2pt \lstset{basicstyle=\ttfamily, diff --git a/preface.tex b/preface.tex index 762abb1..18d30c3 100644 --- a/preface.tex +++ b/preface.tex @@ -1,3 +1,4 @@ \chapter{Preface} -Preface to Learn C The Hard Way. +You can grab the \href{http://learncodethehardway.org/LearnCTheHardWay-preview.pdf}{PDF Preview} +to take a look. Otherwise this is a rough dump of the book as I build the structure.