Skip to content

Commit

Permalink
initial commit, workspace as of 2010-07-08, except for some moved files
Browse files Browse the repository at this point in the history
  • Loading branch information
wardvanwanrooij committed Apr 10, 2017
0 parents commit c81f613
Show file tree
Hide file tree
Showing 133 changed files with 25,199 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
/*.aux
/*.log
/*.out
/*.toc
11 changes: 11 additions & 0 deletions LICENSE
@@ -0,0 +1,11 @@
The C Book - Disclaimer and Copyright Notice

The first edition of this book was based on a late draft of the ANSI standard for C and is copyright Mike Banahan. This online version is a reproduction of the second edition based on the published ANSI standard. The second edition was published in 1991, copyright Mike Banahan, Declan Brady and Mark Doran. By agreement with Declan Brady and Mark Doran, copyright in this online version and derived works is copyright Mike Banahan, 2003. The print versions were published by Addison Wesley.

This online version is derived from files in Unix nroff format discovered on a floppy disk just prior to a move of offices by GBdirect Ltd. It is believed that the files were were used by the publishers Addison Wesley in the preparation of the second print edition and that some amendments or corrections may have been made in the print version that are not reflected in this online version. The online version was prepared with the assistance of some Perl scripts written by Mike Banahan, by Steve King, who cleaned up the output of the Perl scripts and also by sterling work by Geoff Richards and Aaron Crane who performed magic with XSLT to produce the HTML documents.

The publication of the online version is for historical interest and readers are warned that it should be treated as an historical document. There is now a later standard for the C programming language and this publication cannot be considered current: whilst for the most part the current and the first standard are very close, some substantive changes and extensions have occurred since 1991. NO WARRANTY IS OFFERED AS TO THE COMPLETENESS OR ACCURACY OF THE MATERIAL.

Permission is hereby granted for anyone to do anything that they want with this material: you may freely reprint it, redistribute it, amend it or do whatever you like with it provided that you include an acknowledgement of the original authorship and copyright in the form of a link to this page. In doing so you must accept that you do so strictly on your own liability and that you accept any consequences with no liability whatsoever remaining with the original authors. If you find the material useful and happen to encounter one of the authors, it is unlikely that they will refuse offers to buy them a drink. You may therefore like to consider this material 'drinkware'. (Offer void where prohibited by law, in which case fawning and flattery may be substituted.)

Conversion to LaTeX by Ward van Wanrooij.
17,338 changes: 17,338 additions & 0 deletions book.tex

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions example/example1-1.c
@@ -0,0 +1,34 @@
#include <stdio.h>

/*
* Tell the compiler that we intend
* to use a function called show_message.
* It has no arguments and returns no value
* This is the "declaration".
*
*/

void show_message(void);
/*
* Another function, but this includes the body of
* the function. This is a "definition".
*/
main(){
int count;

count = 0;
while(count < 10){
show_message();
count = count + 1;
}

exit(0);
}

/*
* The body of the simple function.
* This is now a "definition".
*/
void show_message(void){
printf("hello\n");
}
30 changes: 30 additions & 0 deletions example/example1-2.c
@@ -0,0 +1,30 @@
/*
*
* Dumb program that generates prime numbers.
*/
#include <stdio.h>
#include <stdlib.h>

main(){
int this_number, divisor, not_prime;

this_number = 3;

while(this_number < 10000){
divisor = this_number / 2;
not_prime = 0;
while(divisor > 1){
if(this_number % divisor == 0){
not_prime = 1;
divisor = 0;
}
else
divisor = divisor-1;
}

if(not_prime == 0)
printf("%d is a prime number\n", this_number);
this_number = this_number + 1;
}
exit(EXIT_SUCCESS);
}
13 changes: 13 additions & 0 deletions example/example1-3.c
@@ -0,0 +1,13 @@
#include <stdio>
#include <stdlib.h>
main(){
int ch;

ch = getchar();
while(ch != 'a'){
if(ch != '\n')
printf("ch was %c, value %d\n", ch, ch);
ch = getchar();
}
exit(EXIT_SUCCESS);
}
50 changes: 50 additions & 0 deletions example/example1-4.c
@@ -0,0 +1,50 @@
#include <stdio>
#include <stdlib.h>
#define ARSIZE 10
main(){
int ch_arr[ARSIZE],count1;
int count2, stop, lastchar;

lastchar = 0;
stop = 0;
/*
* Read characters into array.
* Stop if end of line, or array full.
*/
while(stop != 1){
ch_arr[lastchar] = getchar();
if(ch_arr[lastchar] == '\n')
stop = 1;
else
lastchar = lastchar + 1;
if(lastchar == ARSIZE)
stop = 1;
}
lastchar = lastchar-1;

/*
* Now the traditional bubble sort.
*/
count1 = 0;
while(count1 < lastchar){
count2 = count1 + 1;
while(count2 <= lastchar){
if(ch_arr[count1] > ch_arr[count2]){
/* swap */
int temp;
temp = ch_arr[count1];
ch_arr[count1] = ch_arr[count2];
ch_arr[count2] = temp;
}
count2 = count2 + 1;
}
count1 = count1 + 1;
}

count1 = 0;
while(count1 <= lastchar){
printf("%c\n", ch_arr[count1]);
count1 = count1 + 1;
}
exit(EXIT_SUCCESS);
}
9 changes: 9 additions & 0 deletions example/example10-1.c
@@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
while(argc--)
printf("%s\n", *argv++);
exit(EXIT_SUCCESS);
}
74 changes: 74 additions & 0 deletions example/example10-2.c
@@ -0,0 +1,74 @@
/*
* options() parses option letters and option arguments from the argv list.
* Succesive calls return succesive option letters which match one of
* those in the legal list. Option letters may require option arguments
* as indicated by a ':' following the letter in the legal list.
* for example, a legal list of "ab:c" implies that a, b and c are
* all valid options and that b takes an option argument. The option
* argument is passed back to the calling function in the value
* of the global OptArg pointer. The OptIndex gives the next string
* in the argv[] array that has not already been processed by options().
*
* options() returns -1 if there are no more option letters or if
* double SwitchChar is found. Double SwitchChar forces options()
* to finish processing options.
*
* options() returns '?' if an option not in the legal set is
* encountered or an option needing an argument is found without an
* argument following it.
*
*/

#include <stdio.h>
#include <string.h>

static const char SwitchChar = '-';
static const char Unknown = '?';

int OptIndex = 1; /* first option should be argv[1] */
char *OptArg = NULL; /* global option argument pointer */

int options(int argc, char *argv[], const char *legal)
{
static char *posn = ""; /* position in argv[OptIndex] */
char *legal_index = NULL;
int letter = 0;

if(!*posn){
/* no more args, no SwitchChar or no option letter ? */
if((OptIndex >= argc) ||
(*(posn = argv[OptIndex]) != SwitchChar) ||
!*++posn)
return -1;
/* find double SwitchChar ? */
if(*posn == SwitchChar){
OptIndex++;
return -1;
}
}
letter = *posn++;
if(!(legal_index = strchr(legal, letter))){
if(!*posn)
OptIndex++;
return Unknown;
}
if(*++legal_index != ':'){
/* no option argument */
OptArg = NULL;
if(!*posn)
OptIndex++;
} else {
if(*posn)
/* no space between opt and opt arg */
OptArg = posn;
else
if(argc <= ++OptIndex){
posn = "";
return Unknown;
} else
OptArg = argv[OptIndex];
posn = "";
OptIndex++;
}
return letter;
}

0 comments on commit c81f613

Please sign in to comment.