Skip to content

Commit

Permalink
Laid the foundation of the book and got the tone of it thought out.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedshaw committed Jul 3, 2011
1 parent 225f320 commit c009461
Show file tree
Hide file tree
Showing 61 changed files with 325 additions and 34 deletions.
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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)/

55 changes: 55 additions & 0 deletions book.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion code/ex1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void main()
int main()
{
puts("Hello world.");
}
Expand Down
8 changes: 8 additions & 0 deletions code/ex3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

int main()
{
int age = 10;
printf("I am %d years old\n", age);
}

3 changes: 3 additions & 0 deletions ex0.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 0: The Setup}

This is how you setup your computer to work through this book.
21 changes: 21 additions & 0 deletions ex1.tex
Original file line number Diff line number Diff line change
@@ -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.

3 changes: 3 additions & 0 deletions ex10.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 10}


3 changes: 3 additions & 0 deletions ex11.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 11}


3 changes: 3 additions & 0 deletions ex12.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 12}


3 changes: 3 additions & 0 deletions ex13.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 13}


3 changes: 3 additions & 0 deletions ex14.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 14}


3 changes: 3 additions & 0 deletions ex15.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 15}


3 changes: 3 additions & 0 deletions ex16.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 16}


3 changes: 3 additions & 0 deletions ex17.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 17}


3 changes: 3 additions & 0 deletions ex18.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 18}


3 changes: 3 additions & 0 deletions ex19.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 19}


25 changes: 25 additions & 0 deletions ex2.tex
Original file line number Diff line number Diff line change
@@ -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 ...
3 changes: 3 additions & 0 deletions ex20.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 20}


3 changes: 3 additions & 0 deletions ex21.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 21}


3 changes: 3 additions & 0 deletions ex22.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 22}


3 changes: 3 additions & 0 deletions ex23.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 23}


3 changes: 3 additions & 0 deletions ex24.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 24}


3 changes: 3 additions & 0 deletions ex25.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 25}


3 changes: 3 additions & 0 deletions ex26.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 26}


3 changes: 3 additions & 0 deletions ex27.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 27}


3 changes: 3 additions & 0 deletions ex28.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 28}


3 changes: 3 additions & 0 deletions ex29.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 29}


18 changes: 18 additions & 0 deletions ex3.tex
Original file line number Diff line number Diff line change
@@ -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 ...

3 changes: 3 additions & 0 deletions ex30.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 30}


3 changes: 3 additions & 0 deletions ex31.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 31}


3 changes: 3 additions & 0 deletions ex32.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 32}


3 changes: 3 additions & 0 deletions ex33.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 33}


3 changes: 3 additions & 0 deletions ex34.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 34}


3 changes: 3 additions & 0 deletions ex35.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 35}


3 changes: 3 additions & 0 deletions ex36.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 36}


3 changes: 3 additions & 0 deletions ex37.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 37}


3 changes: 3 additions & 0 deletions ex38.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 38}


3 changes: 3 additions & 0 deletions ex39.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 39}


3 changes: 3 additions & 0 deletions ex4.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 4}


3 changes: 3 additions & 0 deletions ex40.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 40}


3 changes: 3 additions & 0 deletions ex41.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 41}


3 changes: 3 additions & 0 deletions ex42.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 42}


3 changes: 3 additions & 0 deletions ex43.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 43}


3 changes: 3 additions & 0 deletions ex44.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 44}


3 changes: 3 additions & 0 deletions ex45.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 45}


3 changes: 3 additions & 0 deletions ex46.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 46}


3 changes: 3 additions & 0 deletions ex47.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 47}


3 changes: 3 additions & 0 deletions ex48.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 48}


3 changes: 3 additions & 0 deletions ex49.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 49}


3 changes: 3 additions & 0 deletions ex5.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 5}


3 changes: 3 additions & 0 deletions ex50.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 50}


3 changes: 3 additions & 0 deletions ex51.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 51}


3 changes: 3 additions & 0 deletions ex52.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 52}


3 changes: 3 additions & 0 deletions ex6.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 6}


3 changes: 3 additions & 0 deletions ex7.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 7}


3 changes: 3 additions & 0 deletions ex8.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 8}


3 changes: 3 additions & 0 deletions ex9.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Exercise 9}


3 changes: 3 additions & 0 deletions improving.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Thoughts On Improving C}

After decades of using C, I have some ideas for improving it.
Loading

0 comments on commit c009461

Please sign in to comment.