commit - /dev/null
commit + 5dc21454fd1eb9f0d739ecd79df2838189beac11
blob - /dev/null
blob + 2f298dbf4736a2f4d27fae1854ceeec388a3f198 (mode 644)
--- /dev/null
+++ 1-10.c
+/*
+1-10. Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.
+*/
+
+#include <stdio.h>
+
+main()
+{
+ int c;
+
+ while ((c = getchar()) != EOF) {
+ if (c == '\t') {
+ printf("\\t");
+ } else if (c == '\b') {
+ printf("\\b");
+ } else if (c == '\\') {
+ printf("\\\\");
+ } else {
+ printf("%c", c);
+ }
+ }
+}
blob - /dev/null
blob + 3116b7bf1fced378bdc9a14b1b31fea3abd66831 (mode 644)
--- /dev/null
+++ 1-11.c
+#include <stdio.h>
+
+#define IN 1 /* inside a word */
+#define OUT 0 /* outside a word */
+
+/* count lines, words, and characters in input */
+main()
+{
+ int c, nl, nw, nc, state;
+
+ state = OUT;
+ nl = nw = nc = 0;
+ while ((c = getchar()) != EOF) {
+ ++nc;
+ if (c == '\n')
+ ++nl;
+ if (c == ' ' || c == '\n' || c == '\t')
+ state = OUT;
+ else if (state == OUT) {
+ state = IN;
+ ++nw;
+ }
+ }
+ printf("%d %d %d\n", nl, nw, nc);
+}
blob - /dev/null
blob + c728f11aaff700c03d630b7a21e4345ad723f30b (mode 644)
--- /dev/null
+++ 1-12.c
+/*
+1-12. Write a program that prints its input one word per line.
+*/
+
+#include <stdio.h>
+
+main()
+{
+ int c;
+
+ while ((c = getchar()) != EOF) {
+ if (c == ' ' || c == '\n' || c == '\t') {
+ printf("\n");
+ } else {
+ printf("%c", c);
+ }
+ }
+}
blob - /dev/null
blob + dbc013ff3c5ec7770e6c94ae9df6ade06058fa3c (mode 644)
--- /dev/null
+++ 1-13.c
+/* Write a program to print a histogram of the lengths of words in
+ * its input. It is easy to draw the histogram with the bars horizontal;
+ * a vertical orientation is more challenging. */
+
+#include <stdio.h>
+#define MAXLENGTH 20
+
+main()
+{
+ int histogram[MAXLENGTH+1], letters, c, maxfreq;
+
+ for (int i = 1; i <= MAXLENGTH; ++i)
+ histogram[i] = 0;
+ letters = 0;
+ maxfreq = 0;
+
+ while ((c = getchar()) != EOF) {
+ if (c == ' ' || c == '\t' || c == '\n') {
+ ++histogram[letters];
+ letters = 0;
+ } else {
+ ++letters;
+ }
+ }
+ ++histogram[letters];
+
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ printf("%2d: %5d", i, histogram[i]);
+ for (int j = 0; j < histogram[i]; ++j) {
+ printf("=");
+ }
+ printf("\n");
+
+ maxfreq = (histogram[i] > maxfreq ? histogram[i] : maxfreq);
+ }
+ printf("\n\n");
+ for (int h = maxfreq; h > 0; --h) {
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ if (histogram[i] >= h) {
+ printf(" | ");
+ } else {
+ printf(" ");
+ }
+ }
+ printf("\n");
+ }
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ printf("===");
+ }
+ printf("\n");
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ printf("%2d ",i);
+ }
+ printf("\n");
+}
blob - /dev/null
blob + 51b57375d44803f8d298d2034ae9de715c0cdc50 (mode 644)
--- /dev/null
+++ 1-14.c
+/* Write a program to print a histogram of the frequencies of
+ * different characters in its input. */
+
+#include <stdio.h>
+#define CHARSIZE 256
+
+main()
+{
+ int histogram[CHARSIZE], c, maxfreq;
+
+ for (int i = 0; i < CHARSIZE; ++i)
+ histogram[i] = 0;
+
+ maxfreq = 0;
+
+ while ((c = getchar()) != EOF) {
+ ++histogram[c];
+ }
+ for (int i = '0'; i <= '9'; ++i) {
+ printf("%c: %6d\n", i, histogram[i]);
+ }
+ for (int i = 'A'; i <= 'Z'; ++i) {
+ printf("%c: %6d\n", i, histogram[i]);
+ }
+ for (int i = 'a'; i <= 'z'; ++i) {
+ printf("%c: %6d\n", i, histogram[i]);
+ }
+ /*
+ ++histogram[letters];
+
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ printf("%2d: %5d", i, histogram[i]);
+ for (int j = 0; j < histogram[i]; ++j) {
+ printf("=");
+ }
+ printf("\n");
+
+ maxfreq = (histogram[i] > maxfreq ? histogram[i] : maxfreq);
+ }
+ printf("\n\n");
+ for (int h = maxfreq; h > 0; --h) {
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ if (histogram[i] >= h) {
+ printf(" | ");
+ } else {
+ printf(" ");
+ }
+ }
+ printf("\n");
+ }
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ printf("===");
+ }
+ printf("\n");
+ for (int i = 1; i <= MAXLENGTH; ++i) {
+ printf("%2d ",i);
+ }
+ printf("\n");
+ */
+}
blob - /dev/null
blob + dd5cd50846dbd6a9dbb4dbe8b2e73fcbd21f060f (mode 644)
--- /dev/null
+++ 1-15.c
+/* 1-14. Rewrite the temperature conversion program of Section 1.2 to use
+ * a function for converstion.
+ */
+
+#include <stdio.h>
+
+main()
+{
+ for (int fahr = 0; fahr <= 300; fahr = fahr + 20)
+ printf("%3d %6.1f\n", fahr, f2c(fahr));
+}
+
+float f2c(float fahr)
+{
+ return (5.0/9.0)*(fahr-32);
+}
blob - /dev/null
blob + 1517cead019f87c477affdcd79490bc22cfd4348 (mode 644)
--- /dev/null
+++ 1-16.c
+/* 1-16. Revise the main routine of the longest-line program so it will
+ * correctly print the length of arbitrarily long input lines, and as much
+ * as possible of the text.
+ */
+
+/* MAXLINE has been reduced for easier testing */
+#include <stdio.h>
+#define MAXLINE 10
+
+int getlin(char line[], int maxline);
+void copy(char to[], char from[]);
+
+main()
+{
+ int len; /* current line length */
+ int max; /* maximum length seen so far */
+ char line[MAXLINE]; /* current input line */
+ char longest[MAXLINE]; /* longest line saved here */
+
+ max = 0;
+ while ((len = getlin(line, MAXLINE)) > 0)
+ if (len > max) {
+ max = len;
+ copy(longest, line);
+ }
+ if (max > 0) /* there was a line */
+ printf("%d chars: %s", max, longest);
+ return 0;
+}
+
+int getlin(char s[], int lim)
+{
+ int c, i;
+
+ for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
+ s[i] = c;
+ if (c == '\n') {
+ s[i] = c;
+ ++i;
+ }
+ s[i] = '\0';
+ while ((c=getchar())!=EOF && c!='\n')
+ ++i;
+ return i;
+}
+
+void copy(char to[], char from[])
+{
+ int i;
+ i = 0;
+ while ((to[i] = from[i]) != '\0')
+ ++i;
+}
blob - /dev/null
blob + 8b732dedab6d73ee8ddb1a8ffb873129a789058e (mode 644)
--- /dev/null
+++ 1-17.c
+/* 1-17. Write a program to print all input lines that are longer than 80
+ * characters
+ */
+
+/* MAXLINE has been reduced for easier testing */
+#include <stdio.h>
+#define MAXLINE 1000
+
+int getlin(char line[], int maxline);
+void copy(char to[], char from[]);
+
+main()
+{
+ int len; /* current line length */
+ char line[MAXLINE]; /* current input line */
+
+ while ((len = getlin(line, MAXLINE)) > 0) {
+ if (len > 80)
+ printf("%s", line);
+ }
+ return 0;
+}
+
+int getlin(char s[], int lim)
+{
+ int c, i;
+
+ for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
+ s[i] = c;
+ if (c == '\n') {
+ s[i] = c;
+ ++i;
+ }
+ s[i] = '\0';
+ return i;
+}
+
+void copy(char to[], char from[])
+{
+ int i;
+ i = 0;
+ while ((to[i] = from[i]) != '\0')
+ ++i;
+}
blob - /dev/null
blob + c5f98d0192e6316a08bb8af1aca6b794947b5f7d (mode 644)
--- /dev/null
+++ 1-18.c
+/* 1-18. Write a program to remove trailing blanks and tabs from each
+ * line of input, and to delete entirely blank lines.
+ */
+
+/* MAXLINE has been reduced for easier testing */
+#include <stdio.h>
+#define MAXLINE 1000
+
+int getlin(char line[], int maxline);
+void copy(char to[], char from[]);
+
+main()
+{
+ int len; /* current line length */
+ char line[MAXLINE]; /* current input line */
+
+ while ((len = getlin(line, MAXLINE)) > 0) {
+ if (line[0] != '\0')
+ printf("%s\n", line);
+ }
+ return 0;
+}
+
+int getlin(char s[], int lim)
+{
+ int c, i, nullchar;
+ nullchar = 0;
+
+ for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i) {
+ if (c != '\t' && c != ' ') {
+ nullchar = i+1;
+ }
+ s[i] = c;
+ }
+ if (c == '\n')
+ ++i;
+ s[nullchar] = '\0';
+ return i;
+}
+
+void copy(char to[], char from[])
+{
+ int i;
+ i = 0;
+ while ((to[i] = from[i]) != '\0')
+ ++i;
+}
blob - /dev/null
blob + 1115a8c8b8f26a5779a63b061e4ce73a46a04072 (mode 644)
--- /dev/null
+++ 1-19.c
+/*
+ * 1-19. Write a function reverse(s) that reverses the character string s.
+ * Use it to write a program that reverses its input a line at a time.
+ */
+
+/* MAXLINE has been reduced for easier testing */
+#include <stdio.h>
+#define MAXLINE 1000
+
+int getlin(char line[], int maxline);
+void copy(char to[], char from[]);
+int strln(char s[]);
+void rverse(char s[]);
+
+main()
+{
+ int len; /* current line length */
+ char line[MAXLINE]; /* current input line */
+
+ while ((len = getlin(line, MAXLINE)) > 0) {
+ rverse(line);
+ printf("%s\n", line);
+ }
+ return 0;
+}
+
+int strln(char s[])
+{
+ int i;
+ for (i=0; s[i] != '\0'; ++i)
+ ;
+ return i;
+}
+
+void rverse(char s[])
+{
+ int i, len;
+ char c;
+ len = strln(s);
+
+ for (i = 0; i < len/2; ++i) {
+ c = s[i];
+ s[i] = s[len-1-i];
+ s[len-1-i] = c;
+ }
+}
+
+int getlin(char s[], int lim)
+{
+ int c, i;
+
+ for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
+ s[i] = c;
+ if (c == '\n') {
+ ++i;
+ }
+ s[i] = '\0';
+ return i;
+}
+
+void copy(char to[], char from[])
+{
+ int i;
+ i = 0;
+ while ((to[i] = from[i]) != '\0')
+ ++i;
+}
blob - /dev/null
blob + ac939b69f62334de86d70005eee92532af276c3b (mode 644)
--- /dev/null
+++ 1-20.c
+/*
+ * 1-20. Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?
+ */
+
+#include <stdio.h>
+#define TABSTOP 8
+
+main()
+{
+ int c;
+ int col = 1, i;
+ while ((c = getchar())!=EOF) {
+ if (c == '\t') {
+ for (i = 0; i == 0 || (i+col-1)%TABSTOP != 0; ++i) {
+ printf(" ");
+ }
+ col += i;
+ } else {
+ printf("%c", c);
+ ++col;
+ if (c == '\n')
+ col = 1;
+ }
+ }
+}
blob - /dev/null
blob + 25e50d35fd1ee101a16ad4af7e51107e8b551c38 (mode 644)
--- /dev/null
+++ 1-20.txt
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + c995714b96441c0a0844b33f045aa8b41aa82694 (mode 644)
--- /dev/null
+++ 1-20.txt.out
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + a8df5f8ee841c17a235095cc95fd68f7bfa267cb (mode 644)
--- /dev/null
+++ 1-21.c
+/*
+ * 1-21. Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When either a tab or a single blank would suffice to reach a tab stop, which should be given preference?
+ */
+
+#include <stdio.h>
+#define TABSTOP 8
+
+main()
+{
+ int c, col, spaces;
+
+ for (col = 1, spaces = 0; (c = getchar())!=EOF; ++col) {
+ if (c == ' ') {
+ if (col%TABSTOP == 0) {
+ printf ("\t");
+ spaces = 0;
+ } else {
+ ++spaces;
+ }
+ } else if (c == '\t') {
+ do {
+ printf(" ");
+ ++col;
+ } while (col%TABSTOP != 1);
+ } else {
+ for (int i = 0; i < spaces; ++i) {
+ printf(" ");
+ }
+ spaces = 0;
+ printf("%c", c);
+ if (c == '\n') {
+ col = 0;
+ }
+ }
+ }
+}
blob - /dev/null
blob + 1a03608f4aed732c3f272638a56fdd01bbc85810 (mode 644)
--- /dev/null
+++ 1-21.txt
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + 11e1d1973ebc9428503e5fb7394dc586e32a5a2f (mode 644)
--- /dev/null
+++ 1-21.txt.out
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + 64a5313aa41b282ecbb20d5db177d972812184d8 (mode 644)
--- /dev/null
+++ 1-22.c
+/*
+ * 1-22. Write a program to "fold" long input lines into two or more shorter
+ * lines after the last non-blank character that occurs before the n-th
+ * column of input. Make sure your program does something intelligent with
+ * very long lines, and if there are no blanks or tabs before the specified
+ * column.
+ */
+
+#include <stdio.h>
+#define WIDTH 80
+#define TABSTOP 8
+
+int strln(char s[]);
+void copy(char to[], char from[]);
+
+main()
+{
+ int c, i, ci;
+ char current[WIDTH+1];
+ int len;
+
+ ci = i = 0;
+
+ while ((c = getchar())!=EOF) {
+ if (c == ' ') {
+ current[ci] = '\0';
+ len = strln(current)+1;
+ if (i+len <= WIDTH) {
+ printf("%s%c", current, c);
+ i += len;
+ } else {
+ printf("\n%s%c", current, c);
+ i = len;
+ }
+ ci = 0;
+ } else if (c == '\n') {
+ current[ci] = '\0';
+ printf("%s%c", current, c);
+ ci = i = 0;
+ } else if (c == '\t') {
+ len = strln(current)+TABSTOP;
+ current[ci] = '\0';
+ if (i+len <= WIDTH) {
+ printf("%s%c", current, c);
+ i += len;
+ } else {
+ printf("\n%s%c", current, c);
+ i = len;
+ }
+ ci = 0;
+ } else {
+ len = strln(current)+1;
+ if (i+len <= WIDTH) {
+ current[ci] = c;
+ ++ci;
+ } else {
+ current[ci] = '\0';
+ printf("%s\n%c", current, c);
+ ci = 0;
+ i = 1;
+ }
+ }
+ current[ci] = '\0';
+ }
+}
+int strln(char s[])
+{
+ int i;
+ for (i=0; s[i] != '\0'; ++i)
+ ;
+ return i;
+}
+void copy(char to[], char from[])
+{
+ int i;
+ i = 0;
+ while ((to[i] = from[i]) != '\0')
+ ++i;
+}
blob - /dev/null
blob + e360cf49ceecc7d3754d9ffba1eec9f4d52d0792 (mode 644)
--- /dev/null
+++ 1-22a.c
+/*
+ * 1-22. Write a program to "fold" long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long lines, and if there are no blanks or tabs before the specified column.
+ */
+
+#include <stdio.h>
+#define WIDTH 80
+#define TABSTOP 8
+
+int strln(char s[]);
+
+main()
+{
+ int c, i, ci;
+ char current[WIDTH];
+ int len;
+
+ ci = i = 0;
+
+ while ((c = getchar())!=EOF) {
+ if (c == ' ') {
+ current[ci] = '\0';
+ len = strln(current)+1;
+ if (i+len < WIDTH) {
+ printf("%s%c", current, c);
+ i += len;
+ } else {
+ printf("\n%s%c", current, c);
+ i = len;
+ }
+ ci = 0;
+ } else if (c == '\n') {
+ current[ci] = '\0';
+ printf("%s%c", current, c);
+ ci = i = 0;
+ } else if (c == '\t') {
+ len = strln(current)+TABSTOP;
+ current[ci] = '\0';
+ if (i+len < WIDTH) {
+ printf("%s%c", current, c);
+ i += len;
+ } else {
+ printf("\n%s%c", current, c);
+ i = len;
+ }
+ ci = 0;
+ } else {
+ current[ci] = c;
+ ++ci;
+ }
+ }
+}
+int strln(char s[])
+{
+ int i;
+ for (i=0; s[i] != '\0'; ++i)
+ ;
+ return i;
+}
blob - /dev/null
blob + e0e567c1d6555a80ed11f20203dc70677a426d74 (mode 644)
--- /dev/null
+++ 1-23.c
+/*
+ * 1-23. Write a program to remove all comments from a C program. Don't forget to handle quoted strings and character constants properly. C comments do not nest.
+ */
+
+#include <stdio.h>
+#define WIDTH 80
+#define TABSTOP 8
+#define BEGINSLASH 0
+#define COMMENT 1
+#define ENDSTAR 2
+#define NOTCOMMENT 3
+#define QUOTE 4
+
+int strln(char s[]);
+void copy(char to[], char from[]);
+
+main()
+{
+ int c;
+ int comment = NOTCOMMENT;
+ while ((c = getchar())!=EOF) {
+ if (comment == BEGINSLASH) {
+ if (c == '*') {
+ comment = COMMENT;
+ } else {
+ printf("/");
+ if (c != '/') {
+ comment = NOTCOMMENT;
+ }
+ }
+ } else if (comment == COMMENT) {
+ if (c == '*') {
+ comment = ENDSTAR;
+ }
+ } else if (comment == ENDSTAR) {
+ if (c == '/') {
+ comment = NOTCOMMENT;
+ } else if (c != '*') {
+ comment = COMMENT;
+ }
+ } else if (comment == NOTCOMMENT) {
+ if (c == '/') {
+ comment = BEGINSLASH;
+ } else {
+ printf("%c", c);
+ }
+ }
+ }
+}
+int strln(char s[])
+{
+ int i;
+ for (i=0; s[i] != '\0'; ++i)
+ ;
+ return i;
+}
+void copy(char to[], char from[])
+{
+ int i;
+ i = 0;
+ while ((to[i] = from[i]) != '\0')
+ ++i;
+}
blob - /dev/null
blob + 8458fd1a02bc8868b82c27bc48a89b69049f1938 (mode 644)
--- /dev/null
+++ 1-23.txt
+////**********/////**///***////
+/* $OpenBSD: locale.h,v 1.11 2017/09/05 03:16:13 schwarze Exp $ */
+/* $NetBSD: locale.h,v 1.6 1994/10/26 00:56:02 cgd Exp $ */
+
+/*
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)locale.h 5.2 (Berkeley) 2/24/91
+ */
+
+#ifndef _LOCALE_H_
+#define _LOCALE_H_
+
+#include <sys/_null.h>
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *int_curr_symbol;
+ char *currency_symbol;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_cs_precedes;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+
+#define LC_ALL 0
+#define LC_COLLATE 1
+#define LC_CTYPE 2
+#define LC_MONETARY 3
+#define LC_NUMERIC 4
+#define LC_TIME 5
+#define LC_MESSAGES 6
+
+#define _LC_LAST 7 /* marks end */
+
+#include <sys/cdefs.h>
+
+#if __POSIX_VISIBLE >= 200809
+
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+
+#define LC_COLLATE_MASK (1 << LC_COLLATE)
+#define LC_CTYPE_MASK (1 << LC_CTYPE)
+#define LC_MONETARY_MASK (1 << LC_MONETARY)
+#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
+#define LC_TIME_MASK (1 << LC_TIME)
+#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
+
+#define LC_ALL_MASK ((1 << _LC_LAST) - 2)
+
+#define LC_GLOBAL_LOCALE ((locale_t)-1)
+
+#endif /* __POSIX_VISIBLE >= 200809 */
+
+
+__BEGIN_DECLS
+struct lconv *localeconv(void);
+char *setlocale(int, const char *);
+
+#if __POSIX_VISIBLE >= 200809
+locale_t duplocale(locale_t);
+void freelocale(locale_t);
+locale_t newlocale(int, const char *, locale_t);
+locale_t uselocale(locale_t);
+#endif
+__END_DECLS
+
+#endif /* _LOCALE_H_ */
+/* $OpenBSD: dumprestore.h,v 1.11 2021/01/21 00:16:36 mortimer Exp $ */
+/* $NetBSD: dumprestore.h,v 1.14 2005/12/26 19:01:47 perry Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)dumprestore.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _PROTOCOLS_DUMPRESTORE_H_
+#define _PROTOCOLS_DUMPRESTORE_H_
+
+/*
+ * TP_BSIZE is the size of file blocks on the dump tapes.
+ * Note that TP_BSIZE must be a multiple of DEV_BSIZE.
+ *
+ * NTREC is the number of TP_BSIZE blocks that are written
+ * in each tape record. HIGHDENSITYTREC is the number of
+ * TP_BSIZE blocks that are written in each tape record on
+ * 6250 BPI or higher density tapes.
+ *
+ * TP_NINDIR is the number of indirect pointers in a TS_INODE
+ * or TS_ADDR record. Note that it must be a power of two.
+ */
+#define TP_BSIZE 1024
+#define NTREC 10
+#define HIGHDENSITYTREC 32
+#define TP_NINDIR (TP_BSIZE/2)
+#define LBLSIZE 16
+#define NAMELEN 64
+
+#define OFS_MAGIC (int)60011
+#define NFS_MAGIC (int)60012
+#ifndef FS_UFS2_MAGIC
+#define FS_UFS2_MAGIC (int)0x19540119
+#endif
+#define CHECKSUM (int)84446
+
+extern union u_spcl {
+ char dummy[TP_BSIZE];
+ struct s_spcl {
+ int32_t c_type; /* record type (see below) */
+ int32_t c_old_date; /* date of this dump */
+ int32_t c_old_ddate; /* date of previous dump */
+ int32_t c_volume; /* dump volume number */
+ int32_t c_old_tapea; /* logical block of this record */
+ uint32_t c_inumber; /* number of inode */
+ int32_t c_magic; /* magic number (see above) */
+ int32_t c_checksum; /* record checksum */
+ union {
+ struct ufs1_dinode __uc_dinode;
+ struct {
+ uint16_t __uc_mode;
+ int16_t __uc_spare1[3];
+ uint64_t __uc_size;
+ int32_t __uc_old_atime;
+ int32_t __uc_atimensec;
+ int32_t __uc_old_mtime;
+ int32_t __uc_mtimensec;
+ int32_t __uc_spare2[2];
+ int32_t __uc_rdev;
+ int32_t __uc_birthtimensec;
+ int64_t __uc_birthtime;
+ int64_t __uc_atime;
+ int64_t __uc_mtime;
+ int32_t __uc_spare4[7];
+ uint32_t __uc_file_flags;
+ int32_t __uc_spare5[2];
+ uint32_t __uc_uid;
+ uint32_t __uc_gid;
+ int32_t __uc_spare6[2];
+ } __uc_ino;
+ } __c_ino;
+ int32_t c_count; /* number of valid c_addr entries */
+ char c_addr[TP_NINDIR]; /* 1 => data; 0 => hole in inode */
+ char c_label[LBLSIZE]; /* dump label */
+ int32_t c_level; /* level of this dump */
+ char c_filesys[NAMELEN]; /* name of dumped file system */
+ char c_dev[NAMELEN]; /* name of dumped device */
+ char c_host[NAMELEN]; /* name of dumped host */
+ int32_t c_flags; /* additional information */
+ int32_t c_old_firstrec; /* first record on volume */
+ int64_t c_date; /* date of this dump */
+ int64_t c_ddate; /* date of previous dump */
+ int64_t c_tapea; /* logical block of this record */
+ int64_t c_firstrec; /* first record on volume */
+ int32_t c_spare[24]; /* reserved for future uses */
+ } s_spcl;
+} u_spcl;
+#define spcl u_spcl.s_spcl
+
+#define c_dinode __c_ino.__uc_dinode
+#define c_mode __c_ino.__uc_ino.__uc_mode
+#define c_spare1 __c_ino.__uc_ino.__uc_spare1
+#define c_size __c_ino.__uc_ino.__uc_size
+#define c_old_atime __c_ino.__uc_ino.__uc_old_atime
+#define c_atime __c_ino.__uc_ino.__uc_atime
+#define c_atimensec __c_ino.__uc_ino.__uc_atimensec
+#define c_mtime __c_ino.__uc_ino.__uc_mtime
+#define c_mtimensec __c_ino.__uc_ino.__uc_mtimensec
+#define c_birthtime __c_ino.__uc_ino.__uc_birthtime
+#define c_birthtimensec __c_ino.__uc_ino.__uc_birthtimensec
+#define c_old_mtime __c_ino.__uc_ino.__uc_old_mtime
+#define c_rdev __c_ino.__uc_ino.__uc_rdev
+#define c_file_flags __c_ino.__uc_ino.__uc_file_flags
+#define c_uid __c_ino.__uc_ino.__uc_uid
+#define c_gid __c_ino.__uc_ino.__uc_gid
+
+/*
+ * special record types
+ */
+#define TS_TAPE 1 /* dump tape header */
+#define TS_INODE 2 /* beginning of file record */
+#define TS_ADDR 4 /* continuation of file record */
+#define TS_BITS 3 /* map of inodes on tape */
+#define TS_CLRI 6 /* map of inodes deleted since last dump */
+#define TS_END 5 /* end of volume marker */
+
+/*
+ * flag values
+ */
+#define DR_NEWHEADER 0x0001 /* new format tape header */
+#define DR_NEWINODEFMT 0x0002 /* new format inodes on tape */
+
+#define DUMPOUTFMT "%-18s %c %s" /* for printf */
+ /* name, level, ctime(date) */
+#define DUMPINFMT "%18s %c %[^\n]\n" /* inverse for scanf */
+
+#endif /* !_PROTOCOLS_DUMPRESTORE_H_ */
blob - /dev/null
blob + 92da0b7e4305595fcdf386ff1ead3ecdd160241c (mode 644)
--- /dev/null
+++ 1-23.txt.out
+//////////
+
+
+
+
+#ifndef _LOCALE_H_
+#define _LOCALE_H_
+
+#include <sys/null.h>
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *int_curr_symbol;
+ char *currency_symbol;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_cs_precedes;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+
+#define LC_ALL 0
+#define LC_COLLATE 1
+#define LC_CTYPE 2
+#define LC_MONETARY 3
+#define LC_NUMERIC 4
+#define LC_TIME 5
+#define LC_MESSAGES 6
+
+#define _LC_LAST 7
+
+#include <sys/defs.h>
+
+#if __POSIX_VISIBLE >= 200809
+
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+
+#define LC_COLLATE_MASK (1 << LC_COLLATE)
+#define LC_CTYPE_MASK (1 << LC_CTYPE)
+#define LC_MONETARY_MASK (1 << LC_MONETARY)
+#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
+#define LC_TIME_MASK (1 << LC_TIME)
+#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
+
+#define LC_ALL_MASK ((1 << _LC_LAST) - 2)
+
+#define LC_GLOBAL_LOCALE ((locale_t)-1)
+
+#endif
+
+
+__BEGIN_DECLS
+struct lconv *localeconv(void);
+char *setlocale(int, const char *);
+
+#if __POSIX_VISIBLE >= 200809
+locale_t duplocale(locale_t);
+void freelocale(locale_t);
+locale_t newlocale(int, const char *, locale_t);
+locale_t uselocale(locale_t);
+#endif
+__END_DECLS
+
+#endif
+
+
+
+
+
+#ifndef _PROTOCOLS_DUMPRESTORE_H_
+#define _PROTOCOLS_DUMPRESTORE_H_
+
+
+#define TP_BSIZE 1024
+#define NTREC 10
+#define HIGHDENSITYTREC 32
+#define TP_NINDIR (TP_BSIZE/)
+#define LBLSIZE 16
+#define NAMELEN 64
+
+#define OFS_MAGIC (int)60011
+#define NFS_MAGIC (int)60012
+#ifndef FS_UFS2_MAGIC
+#define FS_UFS2_MAGIC (int)0x19540119
+#endif
+#define CHECKSUM (int)84446
+
+extern union u_spcl {
+ char dummy[TP_BSIZE];
+ struct s_spcl {
+ int32_t c_type;
+ int32_t c_old_date;
+ int32_t c_old_ddate;
+ int32_t c_volume;
+ int32_t c_old_tapea;
+ uint32_t c_inumber;
+ int32_t c_magic;
+ int32_t c_checksum;
+ union {
+ struct ufs1_dinode __uc_dinode;
+ struct {
+ uint16_t __uc_mode;
+ int16_t __uc_spare1[3];
+ uint64_t __uc_size;
+ int32_t __uc_old_atime;
+ int32_t __uc_atimensec;
+ int32_t __uc_old_mtime;
+ int32_t __uc_mtimensec;
+ int32_t __uc_spare2[2];
+ int32_t __uc_rdev;
+ int32_t __uc_birthtimensec;
+ int64_t __uc_birthtime;
+ int64_t __uc_atime;
+ int64_t __uc_mtime;
+ int32_t __uc_spare4[7];
+ uint32_t __uc_file_flags;
+ int32_t __uc_spare5[2];
+ uint32_t __uc_uid;
+ uint32_t __uc_gid;
+ int32_t __uc_spare6[2];
+ } __uc_ino;
+ } __c_ino;
+ int32_t c_count;
+ char c_addr[TP_NINDIR];
+ char c_label[LBLSIZE];
+ int32_t c_level;
+ char c_filesys[NAMELEN];
+ char c_dev[NAMELEN];
+ char c_host[NAMELEN];
+ int32_t c_flags;
+ int32_t c_old_firstrec;
+ int64_t c_date;
+ int64_t c_ddate;
+ int64_t c_tapea;
+ int64_t c_firstrec;
+ int32_t c_spare[24];
+ } s_spcl;
+} u_spcl;
+#define spcl u_spcl.s_spcl
+
+#define c_dinode __c_ino.__uc_dinode
+#define c_mode __c_ino.__uc_ino.__uc_mode
+#define c_spare1 __c_ino.__uc_ino.__uc_spare1
+#define c_size __c_ino.__uc_ino.__uc_size
+#define c_old_atime __c_ino.__uc_ino.__uc_old_atime
+#define c_atime __c_ino.__uc_ino.__uc_atime
+#define c_atimensec __c_ino.__uc_ino.__uc_atimensec
+#define c_mtime __c_ino.__uc_ino.__uc_mtime
+#define c_mtimensec __c_ino.__uc_ino.__uc_mtimensec
+#define c_birthtime __c_ino.__uc_ino.__uc_birthtime
+#define c_birthtimensec __c_ino.__uc_ino.__uc_birthtimensec
+#define c_old_mtime __c_ino.__uc_ino.__uc_old_mtime
+#define c_rdev __c_ino.__uc_ino.__uc_rdev
+#define c_file_flags __c_ino.__uc_ino.__uc_file_flags
+#define c_uid __c_ino.__uc_ino.__uc_uid
+#define c_gid __c_ino.__uc_ino.__uc_gid
+
+
+#define TS_TAPE 1
+#define TS_INODE 2
+#define TS_ADDR 4
+#define TS_BITS 3
+#define TS_CLRI 6
+#define TS_END 5
+
+
+#define DR_NEWHEADER 0x0001
+#define DR_NEWINODEFMT 0x0002
+
+#define DUMPOUTFMT "%-18s %c %s"
+
+#define DUMPINFMT "%18s %c %[^\n]\n"
+
+#endif
blob - /dev/null
blob + 72c19f1499ef4d2d1bd6c8c678b3ad283c7971cd (mode 644)
--- /dev/null
+++ 1-24.c
+/*
+ * 1-24. Write a program to check a C program for rudimentary syntax errors like unbalanced parentheses, brackets, and braces. Don't forget about quotes, both single and double, escape seqeuences, and comments. (This program is hard if you do it in full generality.)
+ */
blob - /dev/null
blob + 7e1e224c127877f1b91f5a2dfe2c7f373789955c (mode 644)
--- /dev/null
+++ 1-3.c
+/* 1-3 Modify the temperature conversion program to print a heading above the table */
+
+/* 1-4 write a program to print the corresponding celsius to Fahrenheit table */
+
+#include <stdio.h>
+
+/* print Fahrenheit-Celsius table
+ for fahr = 0, 20, ..., 300; floating-point version */
+
+main()
+{
+ float fahr, celsius;
+ int lower, upper, step;
+
+ lower = 0; /* lower limit of temperature table */
+ upper = 300; /* upper limit */
+ step = 20; /* step size */
+
+ fahr = lower;
+ printf("Fahr | Celsius\n");
+ printf("-----+--------\n");
+ while (fahr <= upper) {
+ celsius = (5.0/9.0) * (fahr - 32.0);
+ printf("%4.0f | %6.1f\n", fahr, celsius);
+ fahr = fahr + step;
+ }
+}
blob - /dev/null
blob + 82ac4ca2f4b7678d0fa71085e0b71137cea74eee (mode 644)
--- /dev/null
+++ 1-4.c
+/* 1-3 Modify the temperature conversion program to print a heading above the table */
+
+/* 1-4 write a program to print the corresponding celsius to Fahrenheit table */
+
+#include <stdio.h>
+
+/* print Fahrenheit-Celsius table
+ for fahr = 0, 20, ..., 300; floating-point version */
+
+main()
+{
+ float fahr, celsius;
+ int lower, upper, step;
+
+ lower = 0; /* lower limit of temperature table */
+ upper = 300; /* upper limit */
+ step = 20; /* step size */
+
+ fahr = lower;
+ printf("Fahr | Celsius\n");
+ printf("-----+--------\n");
+ while (fahr <= upper) {
+ celsius = (5.0/9.0) * (fahr - 32.0);
+ printf("%4.0f | %6.1f\n", fahr, celsius);
+ fahr = fahr + step;
+ }
+ printf("\n\n");
+ celsius = lower;
+ printf("Celsius | Fahr\n");
+ printf("--------+-----\n");
+ while (celsius <= upper) {
+ fahr = (9.0/5.0) * celsius + 32.0;
+ printf("%7.1f | %4.0f\n", celsius, fahr);
+ celsius = celsius + step;
+ }
+}
blob - /dev/null
blob + aaccac6ba6c875dc7557e19d9129273ab7feaad5 (mode 644)
--- /dev/null
+++ 1-5.c
+/* 1-5 Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0 */
+
+#include <stdio.h>
+
+/* print Fahrenheit-Celsius table
+ for fahr = 0, 20, ..., 300; floating-point version */
+
+main()
+{
+ float fahr;
+
+ printf("Fahr | Celsius\n");
+ printf("-----+--------\n");
+ for (fahr = 300; fahr >= 0; fahr -= 20) {
+ printf("%4.0f | %6.1f\n", fahr, (5.0/9.0) * (fahr - 32.0));
+ }
+}
blob - /dev/null
blob + 991a13c965d1ea227e3d3e28fec9d7c62e11de3b (mode 644)
--- /dev/null
+++ 1-7.c
+/* Write a program to print the value of EOF. */
+
+#include <stdio.h>
+
+main()
+{
+ printf("EOF: %d", EOF);
+}
blob - /dev/null
blob + b2bd266f1ce2179881aaba7af3858c1563dbe810 (mode 644)
--- /dev/null
+++ 1-8.c
+/*
+1-8. Write a program to count blanks, tabs, and newlines.
+1-9. Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.
+1-10. Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.
+*/
+
+#include <stdio.h>
+
+main()
+{
+ int c, blanks, tabs, nl;
+
+ blanks = 0, tabs = 0, nl = 0;
+ while ((c = getchar()) != EOF) {
+ if (c == '\n') {
+ ++nl;
+ } else if (c == '\t') {
+ ++tabs;
+ } else if (c == ' ') {
+ ++blanks;
+ }
+ }
+ printf("blanks: %d, tabs: %d, newlines: %d\n", blanks, tabs, nl);
+}
blob - /dev/null
blob + b2ce9b6dee97b24f5aa7dc123bc3694348245858 (mode 644)
--- /dev/null
+++ 1-9.c
+/*
+1-9. Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.
+1-10. Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.
+*/
+
+#include <stdio.h>
+#define FALSE 0
+#define TRUE 1
+
+main()
+{
+ int c;
+ int needsSpace;
+
+ needsSpace = FALSE;
+
+ while ((c = getchar()) != EOF) {
+ if (c == ' ') {
+ needsSpace = TRUE;
+ } else {
+ if (needsSpace)
+ printf(" ");
+ printf("%c", c);
+ needsSpace = FALSE;
+ }
+ }
+}
blob - /dev/null
blob + e892dd3ed204aba96933719017f0e68dea39d1f9 (mode 644)
--- /dev/null
+++ 2-1.c
+/*
+ * 2-1. Write a program to determine the ranges of char, short, int, and long variables, both signed and unsigned, by printing appropriate values from standard headers and by direct computation. Harder if you compute them: determine the ranges of the various floating-point types.
+ */
+
+#include <stdio.h>
+#include <limits.h>
+
+main()
+{
+ char c; unsigned char uc;
+ short s; unsigned short us;
+ int i; unsigned int ui;
+ long l; unsigned long ul;
+ long long ll; unsigned long long ull;
+ int cwidth, swidth, iwidth, lwidth, llwidth;
+ for (c = 1, cwidth = 1; c > 0; c <<= 1, ++cwidth)
+ ;
+ for (s = 1, swidth = 1; s > 0; s <<= 1, ++swidth)
+ ;
+ for (i = 1, iwidth = 1; i > 0; i <<= 1, ++iwidth)
+ ;
+ for (l = 1, lwidth = 1; l > 0; l <<= 1, ++lwidth)
+ ;
+ for (ll = 1, llwidth = 1; ll > 0; ll <<= 1, ++llwidth)
+ ;
+ printf("CHAR_WIDTH: %d\n", cwidth);
+ printf("SCHAR_MIN: %d\n", SCHAR_MIN);
+ printf("SCHAR_MIN: %d\n", c);
+ printf("SCHAR_MAX: %d\n", SCHAR_MAX);
+ printf("SCHAR_MAX: %d\n", c^-1);
+ printf("UCHAR_MAX: %d\n", UCHAR_MAX);
+ printf("UCHAR_MAX: %u\n", (unsigned char)-1);
+ printf("CHAR_MIN: %d\n", CHAR_MIN);
+ printf("CHAR_MIN: %d\n", c);
+ printf("CHAR_MAX: %d\n", CHAR_MAX);
+ printf("CHAR_MAX: %d\n", c^-1);
+ printf("SHRT_WIDTH: %d\n", swidth);
+ printf("USHRT_MAX: %d\n", USHRT_MAX);
+ printf("USHRT_MAX: %d\n", (unsigned short)-1);
+ printf("SHRT_MIN: %d\n", SHRT_MIN);
+ printf("SHRT_MIN: %d\n", s);
+ printf("SHRT_MAX: %d\n", SHRT_MAX);
+ printf("SHRT_MAX: %d\n", s^-1);
+ printf("INT_WIDTH: %d\n", iwidth);
+ printf("UINT_MAX: %u\n", UINT_MAX);
+ printf("UINT_MAX: %u\n", (unsigned)-1);
+ printf("INT_MIN: %d\n", INT_MIN);
+ printf("INT_MIN: %d\n", i);
+ printf("INT_MAX: %d\n", INT_MAX);
+ printf("INT_MAX: %d\n", i^-1);
+ printf("LONG_WIDTH: %d\n", lwidth);
+ printf("LONG_MIN: %ld\n", LONG_MIN);
+ printf("LONG_MIN: %ld\n", l);
+ printf("LONG_MAX: %ld\n", LONG_MAX);
+ printf("LONG_MIN: %ld\n", l^-1);
+ printf("ULONG_MAX: %lu\n", ULONG_MAX);
+ printf("ULONG_MAX: %lu\n", (unsigned long)-1);
+ printf("LLONG_WIDTH: %d\n", llwidth);
+ printf("ULLONG_MAX: %llu\n", ULLONG_MAX);
+ printf("ULLONG_MAX: %llu\n", (unsigned long long)-1);
+ printf("LLONG_MIN: %lld\n", LLONG_MIN);
+ printf("LLONG_MIN: %lld\n", ll);
+ printf("LLONG_MAX: %lld\n", LLONG_MAX);
+ printf("LLONG_MIN: %lld\n", ll^-1);
+}
+/*
+char_min
+0
+(~0)
+00000000 0
+00000001 1
+11111110 -2
+11111111 -1
+10000000 -256
+01111111 +255
+
+
+min is
+100000001
+max is
+011111111
+(~0)+1
+*/
blob - /dev/null
blob + f8b9027e1e08bac20be9b141aaaf0fe06422f7a8 (mode 644)
--- /dev/null
+++ 2-10.c
+/*
+ * 2-10. Rewrite the function lower, which converts upper case letters to lower case, with a condition expression instead of if-else.
+ */
+
+int lower(int c)
+{
+ return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
+}
blob - /dev/null
blob + 2ddc797b6178350673a09b11b309b9756c53c2c7 (mode 644)
--- /dev/null
+++ 2-2.c
+/*
+ * 2-2. Write a loop equivalent to the for loop above without using && or ||.
+ */
+
+for (int i = 0; i<lim-1; ++i) {
+ if ((c=getchar()) == '\n')
+ break;
+ if (c == EOF)
+ break;
+ s[i] = c;
+}
blob - /dev/null
blob + e31a09253f3ad5675a6de15738c8d4179a1c5a59 (mode 644)
--- /dev/null
+++ 2-3.c
+/*
+ * 2-3. Write the function htoi(s), which converts a string of hexadecimal
+ * digits (including an optional 0x or 0X) into its equivalent integer
+ * value. The allowable digits are 0 through 9, a through f, and A through F.
+ */
+#include <stdio.h>
+
+unsigned int htoi(const char s[]);
+
+main () {
+ printf("0 %u\n", htoi("0x00000000"));
+ printf("1 %u\n", htoi("0x00000001"));
+ printf("273 %u\n", htoi("0x00000111"));
+ printf("2730 %u\n", htoi("0x00000aaA"));
+ printf("2872373078 %u\n", htoi("0xab34ef56"));
+ printf("4291686144 %u\n", htoi("0XFFcDeF00"));
+ printf("4294967295 %u\n", htoi("0XfffFFFff"));
+ printf("2687823702 %u\n", htoi("a034eF56"));
+ printf("4294967295 %u\n", htoi("fffFFFff"));
+}
+
+unsigned int htoi(const char s[]) {
+ int i = 0;
+ int val = 0;
+ if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
+ i = 2;
+ }
+ for (; s[i] != '\0'; ++i) {
+ if (s[i] >= '0' && s[i] <= '9') {
+ val = 16*val + s[i] - '0';
+ } else if (s[i] >= 'a' && s[i] <= 'f') {
+ val = 16*val + s[i] - 'a' + 10;
+ } else if (s[i] >= 'A' && s[i] <= 'F') {
+ val = 16*val + s[i] - 'A' + 10;
+ }
+ }
+ return val;
+}
blob - /dev/null
blob + 710090ce3115f4d3f3ebda777559264828b508e9 (mode 644)
--- /dev/null
+++ 2-4.c
+/*
+ * 2-4. Write an alternate version of squeeze(s1, s2) that deletes each
+ * character in s1 that matches any character in the string s2.
+ */
+#include <stdio.h>
+
+void squeeze(char s1[], char s2[]);
+char * strchr(const char *s, int c);
+
+main () {
+ char haystack[] = "The quick brown fox jumped over the lazy dog.";
+ squeeze(haystack, "a");
+ printf("a: %s\n", haystack);
+ squeeze(haystack, "b");
+ printf("b: %s\n", haystack);
+ squeeze(haystack, "c");
+ printf("c: %s\n", haystack);
+ squeeze(haystack, "d");
+ printf("d: %s\n", haystack);
+ squeeze(haystack, "e");
+ printf("e: %s\n", haystack);
+ squeeze(haystack, "f");
+ printf("f: %s\n", haystack);
+ squeeze(haystack, "g");
+ printf("g: %s\n", haystack);
+ squeeze(haystack, "h");
+ printf("h: %s\n", haystack);
+ squeeze(haystack, "i");
+ printf("i: %s\n", haystack);
+ squeeze(haystack, "j");
+ printf("j: %s\n", haystack);
+ squeeze(haystack, "k");
+ printf("k: %s\n", haystack);
+}
+
+void squeeze(char s1[], char s2[]) {
+ int i, j;
+ for (i = j = 0; s1[i] != '\0'; ++i) {
+ if (!strchr(s2, s1[i])) {
+ s1[j++] = s1[i];
+ }
+ }
+ s1[j] = '\0';
+}
+
+char * strchr(const char *s, int c) {
+ int i;
+ for (i = 0; *(s+i) != c; ++i)
+ if (*(s+i) == '\0')
+ return 0;
+ return s+i;
+}
blob - /dev/null
blob + 34cd13457ca9714b798c195d457ca227d4332d5b (mode 644)
--- /dev/null
+++ 2-5.c
+/*
+ * 2-5. Write the function any(s1,s2), which returns the first location in
+ * the string s1 where any character from the string s2 occurs, or -1 if s1
+ * contains no characters from s2. (The standard library function strpbrk
+ * does the same job but returns a pointer to the location.)
+ */
+#include <stdio.h>
+
+int any(char s1[], char s2[]);
+int strchr(const char *s, int c);
+
+main () {
+ printf("2: %d\n", any("The quick brown fox jumped over the lazy dog.", "aeiou"));
+ printf("5: %d\n", any("The quick brown fox jumped over the lazy dog.", "aiou"));
+ printf("6: %d\n", any("The quick brown fox jumped over the lazy dog.", "aio"));
+ printf("12: %d\n", any("The quick brown fox jumped over the lazy dog.", "ao"));
+}
+
+int any(char s1[], char s2[]) {
+ int ret;
+ for (int i = 0; s1[i] != '\0'; ++i)
+ if (strchr(s2,s1[i]))
+ return i;
+ return -1;
+}
+int strchr(const char *s, int c) {
+ int i;
+ for (i = 0; *(s+i) != c; ++i)
+ if (*(s+i) == '\0')
+ return 0;
+ return i;
+}
blob - /dev/null
blob + efbb754806a5a4a2948289af985405c053b33a5a (mode 644)
--- /dev/null
+++ 2-6.c
+/*
+ * 2-6. Write a function setbits(x,p,n,y) that returns x with the n bits
+ * that begin at position p set to the rightmost n bits of y, leaving the
+ * other bits unchanged.
+ */
+
+#include <stdio.h>
+
+unsigned setbits(unsigned x, int p, int n, unsigned y);
+unsigned getbits(unsigned x, int p, int n);
+
+main()
+{
+ printf("%u: %u\n", 0xabcdf211, setbits(0xabcdef01, 12, 9, 0x87654321));
+ printf("%u: %u\n", 0x1ff45678, setbits(0x12345678, 27, 7, 0xffffffff));
+ printf("%u: %u\n", 0x92fab07a, setbits(0x92fab3da, 9, 5, 0x182b3da3));
+ printf("%u: %u\n", 0x1ba95e6a, setbits(0x1ba83dea, 17, 11, 0x29eb3abc));
+}
+
+unsigned setbits(unsigned x, int p, int n, unsigned y)
+{
+ return ((x >> (p+1)) << (p+1)) | (getbits(y, n-1, n) << (p-n+1)) | (x & ~(~0 << (p-n+1)));
+}
+
+/*
+0 0000 1 0001 2 0010 3 0011 4 0100
+5 0101 6 0110 7 0111 8 1000
+a 1010 b 1011 c 1100 d 1101 e 1110 f 1111
+x 1010 1011 1100 1101 1110 1111 0000 0001
+y 1000 0111 0110 0101 0100 0011 0010 0001
+ 1010 1011 1100 1101 1111 0010 0001 0001
+ a b c d f 2 1 1
+
+x 0001 0010 0011 0100 0101 0110 0111 1000
+y 1111 1111 1111 1111 1111 1111 1111 1111
+ 0001 1111 1111 0100 0101 0110 0111 1000
+ 1 f f 4 5 6 7 8
+
+x 1001 0010 1111 1010 1011 0011 1101 1010
+y 0001 1000 0010 1011 0011 1101 1010 0011
+ 1001 0010 1111 1010 1011 0000 0111 1010
+ 9 2 f a b 0 7 a
+
+x 0001 1011 1010 1000 0011 1101 1110 1010
+y 0010 1001 1110 1011 0011 1010 1011 1100
+ 0001 1011 1010 1001 0101 1110 0110 1010
+ 1 b a 9 5 e 6 a
+*/
+
+unsigned getbits(unsigned x, int p, int n)
+{
+ return (x >> (p+1-n)) & ~(~0 << n);
+}
blob - /dev/null
blob + 3fa0e476b145ff6573ef8ced9606b300679916ef (mode 644)
--- /dev/null
+++ 2-7.c
+/*
+ * 2-7. Write a function invert(x,p,n) that returns x with the n bits
+ * that begin at position p inverted (i.e., 1 changed into 0 and vice versa),
+ * leaving the others unchanged.
+ */
+
+#include <stdio.h>
+
+unsigned setbits(unsigned x, int p, int n, unsigned y);
+unsigned getbits(unsigned x, int p, int n);
+unsigned invert(unsigned x, int p, int n);
+
+main()
+{
+ printf("%u: %u\n", 0xabcdf0f1, invert(0xabcdef01, 12, 9));
+ printf("%u: %u\n", 0x1dd45678, invert(0x12345678, 27, 7));
+ printf("%u: %u\n", 0x92fab03a, invert(0x92fab3da, 9, 5));
+ printf("%u: %u\n", 0x1babc26a, invert(0x1ba83dea, 17, 11));
+}
+
+/*
+a b c d e f 0 1
+1010 1011 1100 1101 1110 1111 0000 0001
+1010 1011 1100 1101 1111 0000 1111 0001
+a b c d f 0 f 1
+
+1 2 3 4 5 6 7 8
+0001 0010 0011 0100 0101 0110 0111 1000
+0001 1101 1101 0100 0101 0110 0111 1000
+1 d d 4 5 6 7 8
+
+9 2 f a b 3 d a
+1001 0010 1111 1010 1011 0011 1101 1010
+1001 0010 1111 1010 1011 0000 0011 1010
+9 2 f a b 0 3 a
+
+1 b a 8 3 d e a
+0001 1011 1010 1000 0011 1101 1110 1010
+0001 1011 1010 1011 1100 0010 0110 1010
+1 b a b c 2 6 a
+ */
+
+unsigned invert(unsigned x, int p, int n) {
+ return setbits(x, p, n, ~getbits(x, p, n));
+}
+
+unsigned setbits(unsigned x, int p, int n, unsigned y)
+{
+ return ((x >> (p+1)) << (p+1)) | (getbits(y, n-1, n) << (p-n+1)) | (x & ~(~0 << (p-n+1)));
+}
+
+unsigned getbits(unsigned x, int p, int n)
+{
+ return (x >> (p+1-n)) & ~(~0 << n);
+}
blob - /dev/null
blob + 870ef8eca0204ca5f2959a4f8226bf4809462f6c (mode 644)
--- /dev/null
+++ 2-8.c
+/*
+ * 2-8. Write a function rightrot(x,n) that returns the value of the
+ * integer x rotated to the right by n bit positions.
+ */
+
+#include <stdio.h>
+
+unsigned setbits(unsigned x, int p, int n, unsigned y);
+unsigned getbits(unsigned x, int p, int n);
+unsigned invert(unsigned x, int p, int n);
+unsigned rightrot(unsigned x, int n);
+
+main()
+{
+ printf("%u: %u\n", 0xf01abcde, rightrot(0xabcdef01, 12));
+ printf("%u: %u\n", 0x468acf02, rightrot(0x12345678, 27));
+ printf("%u: %u\n", 0xed497d59, rightrot(0x92fab3da, 9));
+ printf("%u: %u\n", 0x1ef50dd4, rightrot(0x1ba83dea, 17));
+}
+/*
+a b c d e f 0 1
+1010 1011 1100 1101 1110 1111 0000 0001
+1111 0000 0001 1010 1011 1100 1101 1110
+f 0 1 a b c d e
+
+1 2 3 4 5 6 7 8
+0001 0010 0011 0100 0101 0110 0111 1000
+0100 0110 1000 1010 1100 1111 0000 0010
+4 6 8 a c f 0 2
+
+9 2 f a b 3 d a
+1001 0010 1111 1010 1011 0011 1101 1010
+1110 1101 0100 1001 0111 1101 0101 1001
+e d 4 9 7 d 5 9
+
+1 b a 8 3 d e a
+0001 1011 1010 1000 0011 1101 1110 1010
+0001 1110 1111 0101 0000 1101 1101 0100
+1 e f 5 0 d d 4
+ */
+unsigned rightrot(unsigned x, int n) {
+ return (x >> n) | setbits(0,31,n,x);
+}
+
+unsigned invert(unsigned x, int p, int n) {
+ return setbits(x, p, n, ~getbits(x, p, n));
+}
+
+unsigned setbits(unsigned x, int p, int n, unsigned y)
+{
+ return ((x >> (p+1)) << (p+1)) | (getbits(y, n-1, n) << (p-n+1)) | (x & ~(~0 << (p-n+1)));
+}
+
+unsigned getbits(unsigned x, int p, int n)
+{
+ return (x >> (p+1-n)) & ~(~0 << n);
+}
blob - /dev/null
blob + 555dfd1442ed825e4c5cc4219dfa703da4003907 (mode 644)
--- /dev/null
+++ 2-9.c
+/*
+ * 2-9. In a two's complement number system, x &= (x-1) deletes the
+ * rightmost 1-bit in x. Explain why. Use this observation to write a
+ * faster version of bitcount.
+ */
+
+/*
+When you subtract 1 from x, the new number will differ by
+x by 2 bits -- the rightmost 1-bit in x, and the next bit.
+
+When you bitwise and the two, both become 0. This deletes
+the rightmost 1-bit in x.
+
+Illustrated:
+x: 1010 1010
+x-1: 1010 1001
+x&=(x-1): 1010 1000
+*/
+
+#include <stdio.h>
+
+int bitcount(unsigned x);
+unsigned setbits(unsigned x, int p, int n, unsigned y);
+unsigned getbits(unsigned x, int p, int n);
+unsigned invert(unsigned x, int p, int n);
+unsigned rightrot(unsigned x, int n);
+
+main()
+{
+ printf("%u: %d %d\n", 0x8ab30d3a, bitcount(0x8ab30d3a), 15);
+ printf("%u: %d %d\n", 0x37ab16de, bitcount(0x37ab16de), 19);
+ printf("%u: %d %d\n", 0x6de9bcd7, bitcount(0x6de9bcd7), 21);
+}
+
+/*
+8 a b 3 0 d 3 a
+1000 1010 1011 0011 0000 1101 0011 1010
+
+3 7 a b 1 6 d e
+0011 0111 1010 1011 0001 0110 1101 1110
+
+6 d e 9 b c d 7
+0110 1101 1110 1001 1011 1100 1101 0111
+ */
+int bitcount(unsigned x) {
+ int i;
+ for (i = 0; x > 0; x &= (x-1), ++i);
+ return i;
+}
+unsigned rightrot(unsigned x, int n) {
+ return (x >> n) | setbits(0,31,n,x);
+}
+
+unsigned invert(unsigned x, int p, int n) {
+ return setbits(x, p, n, ~getbits(x, p, n));
+}
+
+unsigned setbits(unsigned x, int p, int n, unsigned y)
+{
+ return ((x >> (p+1)) << (p+1)) | (getbits(y, n-1, n) << (p-n+1)) | (x & ~(~0 << (p-n+1)));
+}
+
+unsigned getbits(unsigned x, int p, int n)
+{
+ return (x >> (p+1-n)) & ~(~0 << n);
+}
blob - /dev/null
blob + b310dab7a45a0122977bf96325ac7269dd1f8561 (mode 644)
--- /dev/null
+++ 3-1.c
+/*
+ * 3-1. Our binary search makes two tests inside the loop, when one would
+ * suffice (at the price of more tests outside). Write a version with only
+ * one test inside the loop and measure the difference in run time.
+ */
+
+#include <stdio.h>
+
+main()
+{
+ int v[] = {1,3,6,12,27,31,32,35,39,52,91,102,103,107,109};
+ printf ("%d: %d\n", binsearch(103, v, 15), 12);
+ printf ("%d: %d\n", binsearch(31, v, 15), 5);
+}
+
+int binsearch(int x, int v[], int n)
+{
+ int low, high, mid;
+
+ low = 0;
+ high = n - 1;
+ while (low < high) {
+ mid = (low+high)/2;
+ if (x < v[mid])
+ high = mid - 1;
+ else
+ low = mid;
+ }
+ if (x == v[mid])
+ return mid;
+ return -1;
+}
+/*
+int binsearch(int x, int v[], int n)
+{
+ int low, high, mid;
+
+ low = 0;
+ high = n - 1;
+ while (low <= high) {
+ mid = (low+high)/2;
+ if (x < v[mid])
+ high = mid - 1;
+ else if (x > v[mid])
+ low = mid + 1;
+ else
+ return mid;
+ }
+ return -1;
+}
+*/
blob - /dev/null
blob + 1171487e78239f923669cc83ec796f2c456f39db (mode 644)
--- /dev/null
+++ 3-2.c
+/*
+ * 3-2. Write a function escape(s,t) that converts characters like newline
+ * and tab into visible escape sequences like \n and \t as it copies the
+ * string t to s. Use a switch. Write a function for the other direction as
+ * well, converting escape sequences into the real characters.
+ */
+
+#include <stdio.h>
+
+void escape(char s[], char t[]);
+
+main()
+{
+ char str[400];
+ escape (str, "This\t\t\t is a test\n to see\n\t\t if escaping works");
+ printf("%s\n", str);
+}
+
+void escape(char s[], char t[]) {
+ int i, j;
+ for (i = 0, j = 0; t[j] != '\0'; ++i, ++j) {
+ switch (t[j]) {
+ case '\t':
+ s[i++] = '\\';
+ s[i] = 't';
+ break;
+ case '\n':
+ s[i++] = '\\';
+ s[i] = 'n';
+ break;
+ default:
+ s[i] = t[j];
+ break;
+ }
+ }
+ s[i] = t[j];
+}
blob - /dev/null
blob + 49145afdf7c357891b80e6a08a5ce688196b4e63 (mode 644)
--- /dev/null
+++ 3-3.c
+/*
+ * Exercise 3-3. Write a function expand(s1, s2) that expands shorthand
+ * notations like a-z in the string s1 into the equivalent complete list
+ * abc...xyz in s2. Allow for letters of either case and digits, and be
+ * prepared to handle cases like a-b-c and a-z0-9 and -a-z. Arrange that
+ * a leading or trailing - is taken literally.
+ */
+
+#include <stdio.h>
+
+int expand(char *s1, char *s2);
+
+int main()
+{
+ char expansion[200];
+ expand("a-z", expansion);
+ printf("Expect: abcdefghijlkmnopqrstuvwxyz\n");
+ printf("Result: %s\n", expansion);
+ expand("A-Z", expansion);
+ printf("Expect: ABCDEFGHIJLKMNOPQRSTUVWXYZ\n");
+ printf("Result: %s\n", expansion);
+ expand("0-9", expansion);
+ printf("Expect: 0123456789\n");
+ printf("Result: %s\n", expansion);
+ expand("a-z0-9", expansion);
+ printf("Expect: abcdefghijlkmnopqrstuvwxyz0123456789\n");
+ printf("Result: %s\n", expansion);
+ expand("-a-z", expansion);
+ printf("Expect: -abcdefghijlkmnopqrstuvwxyz\n");
+ printf("Result: %s\n", expansion);
+ expand("a-b-c", expansion);
+ printf("Expect: abc\n");
+ printf("Result: %s\n", expansion);
+ return 0;
+}
+
+/* return value is number of expansions */
+int expand(char *s1, char *s2) {
+ int expansions = 0;
+ char prev = '\0';
+ char next;
+ while (*s1) {
+ if (*s1 == '-') {
+ next = *(s1+1);
+ if ((prev >= 'a' && next <= 'z') ||
+ (prev >= 'A' && next <= 'Z') ||
+ (prev >= '0' && next <= '9')) {
+ prev++; /* first letter copied by default */
+ expansions++;
+ while (prev < next) { /* last letter copied by default */
+ *s2++ = prev++;
+ }
+ s1++;
+ }
+ }
+ prev = *s2++ = *s1++;
+ }
+ *s2 = '\0';
+ return expansions;
+}
blob - /dev/null
blob + e38977a04eb424158b305947342956f90659094e (mode 644)
--- /dev/null
+++ 3-4.c
+/*
+ * Exercise 3-4. In a two's complement number representation, our version of
+ * itoa does not handle the largest negative number, that is, the value of n
+ * equal to -(2^(wordsize-1)). Explain why not. Modify it to print that value
+ * correctly, regardless of the machine on which it runs.
+ */
+
+/* In the step n = -n, it is not possible to negate the largest negative
+ * number without integer overflow.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <limits.h>
+
+void reverse(char s[]) {
+ int c, i, j;
+ for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
+ c = s[i];
+ s[i] = s[j];
+ s[j] = c;
+ }
+}
+
+void itoa(int n, char s[]) {
+ int i, sign;
+ unsigned u;
+ if ((sign = n) < 0)
+ u = -n;
+ i = 0;
+ do {
+ s[i++] = u % 10 + '0';
+ } while ((u /= 10) > 0);
+ if (sign < 0)
+ s[i++] = '-';
+ s[i] = '\0';
+ reverse(s);
+}
+
+int main() {
+ /* word size is 32 bits */
+ char s[100];
+ int i = -147483648;
+ itoa(i, s);
+ printf("Actual: %s\n", s);
+ printf("Expect: %s\n", "-147483648");
+ i = INT_MIN+1;
+ itoa(i, s);
+ printf("Actual: %s\n", s);
+ printf("Expect: %d\n", INT_MIN+1);
+ i = INT_MIN;
+ itoa(i, s);
+ printf("Actual: %s\n", s);
+ printf("Expect: %d\n", INT_MIN);
+ return 0;
+}
blob - /dev/null
blob + 7db81f8b959b6b2b65d414cbd587b8feef0fc64e (mode 644)
--- /dev/null
+++ 3-5.c
+/*
+ * Exercise 3-5. Write the function itob(n,s,b) that converts the integer n
+ * into a base b character representation in the string s. In particular,
+ * itob(n,s,16) formats n tas a hexadecimal integer in s.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+int pow(int x, int n) {
+ int val;
+ for (val = 1; n > 0; n--) {
+ val *= x;
+ }
+ return val;
+}
+int itob(int n, char *s, int b) {
+ char *tr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ int digits;
+ for (digits = 0; pow(b,digits) <= n; digits++)
+ ;
+ for (int i = digits-1; i >= 0; i--) {
+ int times = (n/pow(b,i));
+ *s++ = *(tr + times);
+ n -= times * pow(b,i);
+ }
+ *s = '\0';
+ return 0;
+}
+int assert(char *expect, char *actual) {
+ printf("Expect: %s\n", expect);
+ printf("Actual: %s\n", actual);
+ return strcmp(expect, actual);
+}
+int main() {
+ char s[100];
+ char *t;
+ sprintf(t, "%d", pow(9,9));
+ assert("387420489", t);
+ itob(1208, s, 26);
+ assert("1KC", s);
+ itob(5763, s, 16);
+ assert("1683", s);
+ itob(194200, s, 8);
+ assert("573230", s);
+ itob(2, s, 8);
+ assert("2", s);
+ itob(8, s, 2);
+ assert("1000", s);
+ itob(93, s, 2);
+ assert("1011101", s);
+ /*
+ * overflow issues
+ sprintf(t, "%x", INT_MAX);
+ itob(INT_MAX, s, 16);
+ assert(t, s);
+ */
+}
+
+/*
+ * thought process:
+ * 1208/26
+ * 46.46153846153846153846
+ * too big, repeat division
+ * 1208/26/26
+ * 1.78698224852071005917
+ * base 26: 0100
+ * 1 + modulo
+ * 26*26 = 676
+ * 1208 - 676 = 532
+ * 532 / 26 = 20
+ * lookup 20 (char 9abcdefghijk)
+ * base 26: 01k0 + modulo
+ * 532 - 20*26 = 12
+ * lookup 20 (char c)
+ * base 26: 01kc
+ * 5763/16 = 360.18
+ * too big, repeat division
+ * 5763/16/16 = 22.511
+ * too big, repeat division
+ * 5763/16/16/16 = 1.406
+ * base 16: 1 + modulo
+ * 5763-1*16*16*16 = 1667
+ * 1667/16/16 = 6.5117
+ * 1667-6*16*16 = 131
+ * base 16: 16 + modulo
+ * 131/16 = 8.1875
+ * 131-8*16 = 3
+ * base 16: 163
+ * 194200/8/8/8/8/8 = 5.926
+ * 194200 - 5*8^5 = 30360
+ * 30360/8/8/8/8 = 7.41
+ * 30360 - 7*8^4 = 1688
+ * 1688/8/8/8 = 3.2968
+ * 1688 - 3*8^3 = 152
+ * 152/8/8 = 2.375
+ * 152 - 2*8^2 = 24
+ * 24/8 = 3
+ * base 8: 573230
+ */
+
+/*
+itob(INT_MIN, s, 2);
+printf("Expect: %s\n", "");
+printf("Actual: %s\n", s);
+itob(-5, s, 8);
+printf("Expect: %s\n", "");
+printf("Actual: %s\n", s);
+*/
+
blob - /dev/null
blob + 97bd550e9f114879141ba7c2529e7e1877c261fa (mode 644)
--- /dev/null
+++ 3-6.c
+/*
+ * Exercise 3-6. Write a version of itoa that accepts three arguments instead
+ * of two. The third argument is a minimum field width; the converted number
+ * must be padded with blanks on the left if necessary to make it wide enough.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+void reverse(char s[]) {
+ int c, i, j;
+ for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
+ c = s[i];
+ s[i] = s[j];
+ s[j] = c;
+ }
+}
+
+void itoa(int n, char s[], int width) {
+ int i, sign;
+ if ((sign = n) < 0)
+ n = -n;
+ i = 0;
+ do {
+ s[i++] = n % 10 + '0';
+ } while ((n /= 10) > 0);
+ if (sign < 0)
+ s[i++] = '-';
+ while (i < width) {
+ s[i++] = ' ';
+ }
+ s[i] = '\0';
+ reverse(s);
+}
+
+int assert(char *expect, char *actual) {
+ printf("Expect: %s\n", expect);
+ printf("Actual: %s\n", actual);
+ return strcmp(expect, actual);
+}
+int main() {
+ char s[100];
+ char *t;
+ itoa(231523, s, 10);
+ assert(" 231523", s);
+ itoa(-131523, s, 10);
+ assert(" -131523", s);
+ itoa(34, s, 0);
+ assert("34", s);
+ itoa(-21, s, 0);
+ assert("-21", s);
+ itoa(0, s, 0);
+ assert("0", s);
+ itoa(0, s, 5);
+ assert(" 0", s);
+}
blob - /dev/null
blob + ae9014af0637ba4cc5b1985f949b2e36a6b00657 (mode 644)
--- /dev/null
+++ 4-1.c
+/*
+ * Exercise 4-1. Write the function strrindex(s,t), which returns the position
+ * of the rightmost occurrence of t in s, or -1 if there is none.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#define MAXLINE 1000 /* maximum input line length */
+
+int getlin(char line[], int max);
+int strindex(char source[], char searchfor[]);
+int strrindex(char s[], char t[]);
+
+char pattern[] = "or"; /* pattern to search for */
+
+/* find all lines matching pattern */
+
+int main() {
+ char line[MAXLINE];
+ int found = 0;
+ int index = 0;
+
+ printf("pattern: %s\n", pattern);
+ while (getlin(line, MAXLINE) > 0)
+ if ((index = strrindex(line, pattern)) >= 0) {
+ printf("index: %d, %s", index, line);
+ found++;
+ }
+ return found;
+}
+
+/* getlin: get line into s, return length */
+int getlin(char s[], int lim) {
+ int c, i;
+ i = 0;
+ while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
+ s[i++] = c;
+ if (c == '\n')
+ s[i++] = c;
+ s[i] = '\0';
+ return i;
+}
+
+/* strindex: return index of t in s, -1 if none */
+int strindex(char s[], char t[]) {
+ int i, j, k;
+
+ for (i = 0; s[i] != '\0'; i++) {
+ for (j=i, k=0; t[k] != '\0' && s[j] == t[k]; j++, k++)
+ ;
+ if (k > 0 && t[k] == '\0')
+ return i;
+ }
+ return -1;
+}
+
+/* strrindex: return index of rightmost t in s, -1 if none */
+int strrindex(char s[], char t[]) {
+ int i, j, k;
+ for (i = strlen(s)-1; s[i] != '\0'; i--) {
+ for (j=i, k=0; t[k] != '\0' && s[j] == t[k]; j++, k++)
+ ;
+ if (k > 0 && t[k] == '\0')
+ return i;
+ }
+ return -1;
+}
blob - /dev/null
blob + b45bd9855e008e5c2743fa24453e0e180364689d (mode 644)
--- /dev/null
+++ 4-1.poem
+Ah Love! could you and I with Fate conspire
+To grasp this sorry Scheme of Things entire,
+Would not we shatter it to bits -- and then
+Re-mould it nearer to the Heart's Desire!
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
+nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
+fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+culpa qui officia deserunt mollit anim id est laborum.
blob - /dev/null
blob + e633ca4669bd410a69770ffba8b64e8ad778fb4f (mode 644)
--- /dev/null
+++ 4-10.c
+/*
+ * Exercise 4-10. An alternative organization uses getline to read an entire
+ * input line; this makes getch and ungetch unnecessary. Revise the calculator
+ * to use this approach.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+#include <math.h> /* for math functions */
+#include <string.h> /* for strcmp() */
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+#define IDENTIFIER '1' /* signal that an identifier was found */
+#define VARIABLE '2' /* signal that a variable was found */
+#define ASSIGNMENT '3' /* signal that a variable was found */
+#define LETTERS 26 /* number of letters in alphabet */
+
+int getop(char []);
+void push(double);
+double pop(void);
+double printtop(void);
+int duplicate(void);
+int swap(void);
+void clear(void);
+int assign(char, double);
+double interpolate(char);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2, val;
+ char s[MAXOP];
+ int index;
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case IDENTIFIER:
+ if (strcmp(s, "sin") == 0)
+ push(sin(pop()));
+ else if (strcmp(s, "cos") == 0)
+ push(cos(pop()));
+ else if (strcmp(s, "exp") == 0)
+ push(exp(pop()));
+ break;
+ case VARIABLE:
+ push(interpolate(s[0]));
+ break;
+ case ASSIGNMENT:
+ assign(s[0], atof(s+2));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '?':
+ printf("\t%.8g\n", printtop());
+ break;
+ case '#':
+ if (duplicate() == 0)
+ printf("error: can't duplicate\n");
+ break;
+ case '~':
+ if (swap() == 0)
+ printf("error: swap failed, stack needs two numbers\n");
+ break;
+ case '!':
+ clear();
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#include <ctype.h> /* for tolower() */
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+double var[LETTERS]; /* variable stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* printtop: print the top value of the stack without popping it */
+double printtop(void) {
+ if (sp > 0)
+ return val[sp-1];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* duplicate: duplicate the top value of the stack
+ * return 1 if successful, 0 on failure */
+int duplicate(void) {
+ if (sp <= 0) {
+ return 0;
+ } else if (sp >= MAXVAL) {
+ return 0;
+ } else {
+ val[sp] = val[sp-1];
+ sp++;
+ return 1;
+ }
+}
+
+/* swap: swap the top two values of the stack
+ * return 1 if successful, 0 on failure */
+int swap(void) {
+ if (sp > 1) {
+ int temp = val[sp-1];
+ val[sp-1] = val[sp-2];
+ val[sp-2] = temp;
+ return 1;
+ }
+ return 0;
+}
+
+/* clear: clear the stack */
+void clear(void) {
+ sp = 0;
+}
+
+/* assign: assign a double to a variable
+ * return 1 on success, 0 on failure */
+int assign(char variable, double value) {
+ int index = tolower(variable) - 'a';
+ if (0 <= index && index < LETTERS) {
+ var[index] = value;
+ return 1;
+ }
+ printf("error: assignment failed, variable needs to be single letter\n");
+ return 0;
+}
+
+/* interpolate: interpolate variable */
+double interpolate(char variable) {
+ int index = tolower(variable) - 'a';
+ if (0 <= index && index < LETTERS) {
+ return var[index];
+ }
+ printf("error: variable must be single letter\n");
+ return 0.0;
+}
+
+#include <ctype.h>
+
+/* getlin: get line into s, return length */
+int getlin(char s[], int lim) {
+ int c, i;
+ i = 0;
+ while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
+ s[i++] = c;
+ if (c == '\n' || c == EOF)
+ s[i++] = c;
+ s[i] = '\0';
+ return i;
+}
+
+char buf[MAXOP] = "\n"; /* buffer for current line */
+int bufp = 0; /* next char to scan in buffer */
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i, c;
+ while ((s[0] = c = buf[bufp++]) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ i = 0;
+ if (isalpha(c)) {
+ while ((s[++i] = c = buf[bufp++]) != ' ' && c != '\t' && c != '\n')
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ bufp--;
+ if (s[1] == '=') {
+ return ASSIGNMENT;
+ } else if (s[1] == '\0') {
+ return VARIABLE;
+ } else {
+ return IDENTIFIER;
+ }
+ }
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = buf[bufp++];
+ if (!isdigit(c) && c != '.') {
+ bufp--;
+ return '-';
+ }
+ }
+ if (c == '\n') {
+ getlin(buf, MAXOP);
+ bufp = 0;
+ }
+ if (!isdigit(c) && c != '.')
+ return c; /* not a number */
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = buf[bufp++]))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = buf[bufp++]))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ bufp--;
+ return NUMBER;
+}
blob - /dev/null
blob + d506ebae054c4c1abe016f93077f542fd771614d (mode 644)
--- /dev/null
+++ 4-11.c
+/*
+ * Exercise 4-11. Modify getop so that it doesn't need to use ungetch. Hint:
+ * use an internal static variable.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+#include <math.h> /* for math functions */
+#include <string.h> /* for strcmp() */
+#include <ctype.h> /* for tolower() */
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+#define IDENTIFIER '1' /* signal that an identifier was found */
+#define VARIABLE '2' /* signal that a variable was found */
+#define ASSIGNMENT '3' /* signal that a variable was found */
+#define LETTERS 26 /* number of letters in alphabet */
+
+int getop(char []);
+void push(double);
+double pop(void);
+double printtop(void);
+int duplicate(void);
+int swap(void);
+void clear(void);
+int assign(int, double);
+double eval(int index);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2, val;
+ char s[MAXOP];
+ int index;
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case IDENTIFIER:
+ if (strcmp(s, "sin") == 0)
+ push(sin(pop()));
+ else if (strcmp(s, "cos") == 0)
+ push(cos(pop()));
+ else if (strcmp(s, "exp") == 0)
+ push(exp(pop()));
+ break;
+ case VARIABLE:
+ index = tolower(s[0]) - 'a';
+ if (0 <= index && index < LETTERS) {
+ push(eval(index));
+ } else {
+ printf("error: variable must be single letter\n");
+ }
+ break;
+ case ASSIGNMENT:
+ index = tolower(s[0]) - 'a';
+ val = atof(s+2);
+ if (!assign(index, val)) {
+ printf("error: assignment failed, variable needs to be single letter\n");
+ }
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '?':
+ printf("\t%.8g\n", printtop());
+ break;
+ case '#':
+ if (duplicate() == 0)
+ printf("error: can't duplicate\n");
+ break;
+ case '~':
+ if (swap() == 0)
+ printf("error: swap failed, stack needs two numbers\n");
+ break;
+ case '!':
+ clear();
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+double var[LETTERS]; /* variable stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* printtop: print the top value of the stack without popping it */
+double printtop(void) {
+ if (sp > 0)
+ return val[sp-1];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* duplicate: duplicate the top value of the stack
+ * return 1 if successful, 0 on failure */
+int duplicate(void) {
+ if (sp <= 0) {
+ return 0;
+ } else if (sp >= MAXVAL) {
+ return 0;
+ } else {
+ val[sp] = val[sp-1];
+ sp++;
+ return 1;
+ }
+}
+
+/* swap: swap the top two values of the stack
+ * return 1 if successful, 0 on failure */
+int swap(void) {
+ if (sp > 1) {
+ int temp = val[sp-1];
+ val[sp-1] = val[sp-2];
+ val[sp-2] = temp;
+ return 1;
+ }
+ return 0;
+}
+
+/* clear: clear the stack */
+void clear(void) {
+ sp = 0;
+}
+
+/* assign: assign a double to a variable, letters represented by int from 0-25
+ * return 1 on success, 0 on failure */
+int assign(int index, double value) {
+ if (0 <= index && index < LETTERS) {
+ var[index] = value;
+ return 1;
+ }
+ return 0;
+}
+
+/* eval: evaluate variable, letters represented by int from 0-25 */
+double eval(int index) {
+ if (0 <= index && index < LETTERS) {
+ return var[index];
+ }
+ return 0.0;
+}
+
+#include <ctype.h>
+
+int getch(void);
+void ungetch(int);
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i;
+ static int c = ' ';
+ int op;
+ while (c == ' ' || c == '\t') {
+ c = getchar();
+ }
+ s[0] = c;
+ s[1] = '\0';
+ i = 0;
+ if (isalpha(c)) {
+ while ((s[++i] = c = getch()) != ' ' && c != '\t' && c != '\n')
+ ;
+ s[i] = '\0';
+ if (s[1] == '=') {
+ return ASSIGNMENT;
+ } else if (s[1] == '\0') {
+ return VARIABLE;
+ } else {
+ return IDENTIFIER;
+ }
+ }
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = getch();
+ if (!isdigit(c) && c != '.') {
+ return '-';
+ }
+ }
+ if (!isdigit(c) && c != '.') {
+ op = c;
+ c = ' ';
+ return op; /* not a number */
+ }
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ return NUMBER;
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
blob - /dev/null
blob + d292dbff237c5021e2bb1157de1481a461a3cc1f (mode 644)
--- /dev/null
+++ 4-11.data
+1 2 - 4 5 + *
+-9
+22 7 / 4 3 / + 2 6 + 3 - 9 / -
+3.92063492063492063492
+5 3 % 1 -
+1
+25 7 % 4 * 12 -
+4
+25 7 % 4 * ? 12 -
+16
+4
+-9 -5 -
+-4
+-9 -7 - -3 -
+1
+13 7 * 2 + 15 - 12 ? -
+12
+66
+23 14 - ? 16 4 3 - * ? 2 1 1 + + ? / + 3 %
+9
+16
+4
+1
+23 14 - # * 16 4 3 - * % 2 1 1 + + # * +
+17
+23 14 - # * 16 4 3 - * % 2 1 1 + + # * - 4 /
+-3.75000000000000000000
+4 3 -
+1
+1 !
+23 14 1 3 2 5 1 + + !
+1.571 sin
+1
+3.1415 sin
+0
+1.571 cos
+0
+3.1415 cos
+-1
+1 exp
+2.71828182845904523536
+a=1
+b=2
+c=3
+d=4
+a b c d + / -
+.71428571428571428572
+d c / b a + -
+-1.66667
blob - /dev/null
blob + 4d4de833bd934b34ec54c014039af2d9c0455e55 (mode 644)
--- /dev/null
+++ 4-12.c
+/*
+ * Adapt the ideas of printd to write a recursive version of itoa ; that is,
+ * convert an integer into a string by calling a recursive routine.
+ */
blob - /dev/null
blob + 5b325828475610789568a711facdba8f20af09dd (mode 644)
--- /dev/null
+++ 4-2.c
+/*
+ * Exercise 4-2. Extend atof to handle scientific notation of the form
+ *
+ * 123.45e-6
+ *
+ * where a floating point number may be followed by e or E and an optionally
+ * signed exponent.
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <math.h>
+
+#define MAXLINE 100
+
+/* rudimentary calculator */
+
+double pow(double x, double y);
+
+int main() {
+ double atof(char []);
+ char line[MAXLINE];
+ int getlin(char line[], int max);
+
+ while (getlin(line, MAXLINE) > 0)
+ printf("\t%f\n", atof(line));
+ return 0;
+}
+
+/* getlin: get line into s, return length */
+int getlin(char s[], int lim) {
+ int c, i;
+ i = 0;
+ while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
+ s[i++] = c;
+ if (c == '\n')
+ s[i++] = c;
+ s[i] = '\0';
+ return i;
+}
+
+/* atof: convert string s to double */
+double atof(char s[]) {
+ double val, power;
+ int i, sign, expsign, exp;
+
+ for (i = 0; isspace(s[i]); i++) /* skip white space */
+ ;
+ sign = (s[i] == '-') ? -1 : 1;
+ if (s[i] == '+' || s[i] == '-')
+ i++;
+ for (val = 0.0; isdigit(s[i]); i++)
+ val = 10.0 * val + (s[i] - '0');
+ if (s[i] == '.')
+ i++;
+ for (power = 1.0; isdigit(s[i]); i++) {
+ val = 10.0 * val + (s[i] - '0');
+ power *= 10.0;
+ }
+ if (s[i] == 'e' || s[i] == 'E') {
+ i++;
+ expsign = (s[i] == '-') ? -1 : 1;
+ if (s[i] == '+' || s[i] == '-')
+ i++;
+ for (exp = 0; isdigit(s[i]); i++)
+ exp = 10 * exp + (s[i] - '0');
+ } else {
+ exp = 0;
+ expsign = 1;
+ }
+ return sign * val * pow(10,expsign*exp) / power;
+}
+
+int atoi(char s[]) {
+ double atof(char s[]);
+ return (int) atof(s);
+}
blob - /dev/null
blob + aa99695f9cc4a45e940595df7e83e04cfac315b7 (mode 644)
--- /dev/null
+++ 4-2.data
+123.45e-6
+0.14E-3
+-1.232e3
+142.25
+-15
+10.0
+-20e13
+2e51
+2315
blob - /dev/null
blob + 739c636e04d1944b9dafa81005934e600a9ecf44 (mode 644)
--- /dev/null
+++ 4-3.c
+/*
+ * Exercise 4-3. Given the basic framework, it's straightforward to extend the
+ * calculator. Add the modulus (%) operator and provisions for negative
+ * numbers.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+
+int getop(char []);
+void push(double);
+double pop(void);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2;
+ char s[MAXOP];
+
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+#include <ctype.h>
+
+int getch(void);
+void ungetch(int);
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i, c;
+ while ((s[0] = c = getch()) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ i = 0;
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = getch();
+ if (!isdigit(c) && c != '.') {
+ ungetch(c);
+ return '-';
+ }
+ }
+ if (!isdigit(c) && c != '.')
+ return c; /* not a number */
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ return NUMBER;
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
blob - /dev/null
blob + d0c8a28aec23ee4039d076cde783b33e4a0154dc (mode 644)
--- /dev/null
+++ 4-3.data
+1 2 - 4 5 + *
+-9
+22 7 / 4 3 / + 2 6 + 3 - 9 / -
+3.92063492063492063492
+5 3 % 1 -
+1
+25 7 % 4 * 12 -
+4
+-9 -5 -
+-4
+-9 -7 - -3 -
+1
blob - /dev/null
blob + 534869d6061068697f636762882b5623db9c55ea (mode 644)
--- /dev/null
+++ 4-4.c
+/*
+ * Exercise 4-4. Add commands to print the top element of the stack without
+ * popping, to duplicate it, and to swap the top two elements. Add a command to
+ * clear the stack.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+
+int getop(char []);
+void push(double);
+double pop(void);
+double printtop(void);
+int duplicate(void);
+int swap(void);
+void clear(void);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2;
+ char s[MAXOP];
+
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '?':
+ printf("\t%.8g\n", printtop());
+ break;
+ case '#':
+ if (duplicate() == 0)
+ printf("error: can't duplicate\n");
+ break;
+ case '~':
+ if (swap() == 0)
+ printf("error: swap failed, stack needs two numbers\n");
+ break;
+ case '!':
+ clear();
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* printtop: print the top value of the stack without popping it */
+double printtop(void) {
+ if (sp > 0)
+ return val[sp-1];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* duplicate: duplicate the top value of the stack
+ * return 1 if successful, 0 on failure */
+int duplicate(void) {
+ if (sp <= 0) {
+ return 0;
+ } else if (sp >= MAXVAL) {
+ return 0;
+ } else {
+ val[sp] = val[sp-1];
+ sp++;
+ return 1;
+ }
+}
+
+/* swap: swap the top two values of the stack
+ * return 1 if successful, 0 on failure */
+int swap(void) {
+ if (sp > 1) {
+ int temp = val[sp-1];
+ val[sp-1] = val[sp-2];
+ val[sp-2] = temp;
+ return 1;
+ }
+ return 0;
+}
+
+/* clear: clear the stack */
+void clear(void) {
+ sp = 0;
+}
+
+#include <ctype.h>
+
+int getch(void);
+void ungetch(int);
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i, c;
+ while ((s[0] = c = getch()) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ i = 0;
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = getch();
+ if (!isdigit(c) && c != '.') {
+ ungetch(c);
+ return '-';
+ }
+ }
+ if (!isdigit(c) && c != '.')
+ return c; /* not a number */
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ return NUMBER;
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
blob - /dev/null
blob + 29da3e49d82004e30e98dc2dd6b2288fab10b6e3 (mode 644)
--- /dev/null
+++ 4-4.data
+1 2 - 4 5 + *
+-9
+22 7 / 4 3 / + 2 6 + 3 - 9 / -
+3.92063492063492063492
+5 3 % 1 -
+1
+25 7 % 4 * 12 -
+4
+25 7 % 4 * ? 12 -
+16
+4
+-9 -5 -
+-4
+-9 -7 - -3 -
+1
+13 7 * 2 + 15 - 12 ? -
+12
+66
+23 14 - ? 16 4 3 - * ? 2 1 1 + + ? / + 3 %
+9
+16
+4
+1
+23 14 - # * 16 4 3 - * % 2 1 1 + + # * +
+17
+23 14 - # * 16 4 3 - * % 2 1 1 + + # * - 4 /
+.26666666666666666666
+4 3 -
+-1
+1 !
+23 14 1 3 2 5 1 + + !
blob - /dev/null
blob + 9caafc73f7e41da1ef642fa4ab29af8d0268fbe2 (mode 644)
--- /dev/null
+++ 4-5.c
+/*
+ * Exercise 4-5. Add access to library functions like sin, exp, and pow. See
+ * <math.h> in Appendix B, Section 4.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+#include <math.h>
+#include <string.h>
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+#define IDENTIFIER '1' /* signal that an identifier was found */
+
+int getop(char []);
+void push(double);
+double pop(void);
+double printtop(void);
+int duplicate(void);
+int swap(void);
+void clear(void);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2;
+ char s[MAXOP];
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case IDENTIFIER:
+ if (strcmp(s, "sin") == 0)
+ push(sin(pop()));
+ else if (strcmp(s, "cos") == 0)
+ push(cos(pop()));
+ else if (strcmp(s, "exp") == 0)
+ push(exp(pop()));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '?':
+ printf("\t%.8g\n", printtop());
+ break;
+ case '#':
+ if (duplicate() == 0)
+ printf("error: can't duplicate\n");
+ break;
+ case '~':
+ if (swap() == 0)
+ printf("error: swap failed, stack needs two numbers\n");
+ break;
+ case '!':
+ clear();
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* printtop: print the top value of the stack without popping it */
+double printtop(void) {
+ if (sp > 0)
+ return val[sp-1];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* duplicate: duplicate the top value of the stack
+ * return 1 if successful, 0 on failure */
+int duplicate(void) {
+ if (sp <= 0) {
+ return 0;
+ } else if (sp >= MAXVAL) {
+ return 0;
+ } else {
+ val[sp] = val[sp-1];
+ sp++;
+ return 1;
+ }
+}
+
+/* swap: swap the top two values of the stack
+ * return 1 if successful, 0 on failure */
+int swap(void) {
+ if (sp > 1) {
+ int temp = val[sp-1];
+ val[sp-1] = val[sp-2];
+ val[sp-2] = temp;
+ return 1;
+ }
+ return 0;
+}
+
+/* clear: clear the stack */
+void clear(void) {
+ sp = 0;
+}
+
+#include <ctype.h>
+
+int getch(void);
+void ungetch(int);
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i, c;
+ while ((s[0] = c = getch()) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ i = 0;
+ if (isalpha(c)) {
+ while (isalpha(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ return IDENTIFIER;
+ }
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = getch();
+ if (!isdigit(c) && c != '.') {
+ ungetch(c);
+ return '-';
+ }
+ }
+ if (!isdigit(c) && c != '.')
+ return c; /* not a number */
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ return NUMBER;
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
+
+/*
+void printstack(void);
+ printstack();
+void printstack(void) {
+ for (int i = 0; i < sp; i++)
+ printf("%g ", val[i]);
+ printf("\n");
+}
+*/
blob - /dev/null
blob + 2479b5184e74f48d83fc4c5aa3bb627abe0e6568 (mode 644)
--- /dev/null
+++ 4-5.data
+1.571 sin
+1
+3.1415 sin
+0
+1.571 cos
+0
+3.1415 cos
+-1
+1 exp
+2.71828182845904523536
blob - /dev/null
blob + 08141fd451d12c8458f4059be836d2405e1c272b (mode 644)
--- /dev/null
+++ 4-6-2.c
+/*
+ * Exercise 4-6. Add commands for handling variables. (It's easy to provide
+ * twenty-six variables with single-letter names.) Add a variable for the most
+ * recently printed value.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+#include <math.h> /* for math functions */
+#include <string.h> /* for strcmp() */
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+#define IDENTIFIER '1' /* signal that an identifier was found */
+#define VARIABLE '2' /* signal that a variable was found */
+#define ASSIGNMENT '3' /* signal that a variable was found */
+#define LETTERS 26 /* number of letters in alphabet */
+
+int getop(char []);
+void push(double);
+double pop(void);
+double printtop(void);
+int duplicate(void);
+int swap(void);
+void clear(void);
+int assign(char, double);
+double interpolate(char);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2, val;
+ char s[MAXOP];
+ int index;
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case IDENTIFIER:
+ if (strcmp(s, "sin") == 0)
+ push(sin(pop()));
+ else if (strcmp(s, "cos") == 0)
+ push(cos(pop()));
+ else if (strcmp(s, "exp") == 0)
+ push(exp(pop()));
+ break;
+ case VARIABLE:
+ push(interpolate(s[0]));
+ break;
+ case ASSIGNMENT:
+ assign(s[0], atof(s+2));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '?':
+ printf("\t%.8g\n", printtop());
+ break;
+ case '#':
+ if (duplicate() == 0)
+ printf("error: can't duplicate\n");
+ break;
+ case '~':
+ if (swap() == 0)
+ printf("error: swap failed, stack needs two numbers\n");
+ break;
+ case '!':
+ clear();
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#include <ctype.h> /* for tolower() */
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+double var[LETTERS]; /* variable stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* printtop: print the top value of the stack without popping it */
+double printtop(void) {
+ if (sp > 0)
+ return val[sp-1];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* duplicate: duplicate the top value of the stack
+ * return 1 if successful, 0 on failure */
+int duplicate(void) {
+ if (sp <= 0) {
+ return 0;
+ } else if (sp >= MAXVAL) {
+ return 0;
+ } else {
+ val[sp] = val[sp-1];
+ sp++;
+ return 1;
+ }
+}
+
+/* swap: swap the top two values of the stack
+ * return 1 if successful, 0 on failure */
+int swap(void) {
+ if (sp > 1) {
+ int temp = val[sp-1];
+ val[sp-1] = val[sp-2];
+ val[sp-2] = temp;
+ return 1;
+ }
+ return 0;
+}
+
+/* clear: clear the stack */
+void clear(void) {
+ sp = 0;
+}
+
+/* assign: assign a double to a variable
+ * return 1 on success, 0 on failure */
+int assign(char variable, double value) {
+ int index = tolower(variable) - 'a';
+ if (0 <= index && index < LETTERS) {
+ var[index] = value;
+ return 1;
+ }
+ printf("error: assignment failed, variable needs to be single letter\n");
+ return 0;
+}
+
+/* interpolate: interpolate variable */
+double interpolate(char variable) {
+ int index = tolower(variable) - 'a';
+ if (0 <= index && index < LETTERS) {
+ return var[index];
+ }
+ printf("error: variable must be single letter\n");
+ return 0.0;
+}
+
+#include <ctype.h>
+
+int getch(void);
+void ungetch(int);
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i, c;
+ while ((s[0] = c = getch()) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ i = 0;
+ if (isalpha(c)) {
+ while ((s[++i] = c = getch()) != ' ' && c != '\t' && c != '\n')
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ if (s[1] == '=') {
+ return ASSIGNMENT;
+ } else if (s[1] == '\0') {
+ return VARIABLE;
+ } else {
+ return IDENTIFIER;
+ }
+ }
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = getch();
+ if (!isdigit(c) && c != '.') {
+ ungetch(c);
+ return '-';
+ }
+ }
+ if (!isdigit(c) && c != '.')
+ return c; /* not a number */
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ return NUMBER;
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
blob - /dev/null
blob + b0fa6ce7330501f3bbae2af196a08cdc3e8b87bc (mode 644)
--- /dev/null
+++ 4-6.c
+/*
+ * Exercise 4-6. Add commands for handling variables. (It's easy to provide
+ * twenty-six variables with single-letter names.) Add a variable for the most
+ * recently printed value.
+ */
+
+#include <stdio.h>
+#include <stdlib.h> /* for atof() */
+#include <math.h> /* for math functions */
+#include <string.h> /* for strcmp() */
+#include <ctype.h> /* for tolower() */
+
+#define MAXOP 100 /* max size of operand or operator */
+#define NUMBER '0' /* signal that a number was found */
+#define IDENTIFIER '1' /* signal that an identifier was found */
+#define VARIABLE '2' /* signal that a variable was found */
+#define ASSIGNMENT '3' /* signal that a variable was found */
+#define LETTERS 26 /* number of letters in alphabet */
+
+int getop(char []);
+void push(double);
+double pop(void);
+double printtop(void);
+int duplicate(void);
+int swap(void);
+void clear(void);
+int assign(int, double);
+double eval(int index);
+
+/* reverse Polish calculator */
+int main() {
+ int type;
+ double op2, val;
+ char s[MAXOP];
+ int index;
+ while ((type = getop(s)) != EOF) {
+ switch (type) {
+ case NUMBER:
+ push(atof(s));
+ break;
+ case IDENTIFIER:
+ if (strcmp(s, "sin") == 0)
+ push(sin(pop()));
+ else if (strcmp(s, "cos") == 0)
+ push(cos(pop()));
+ else if (strcmp(s, "exp") == 0)
+ push(exp(pop()));
+ break;
+ case VARIABLE:
+ index = tolower(s[0]) - 'a';
+ if (0 <= index && index < LETTERS) {
+ push(eval(index));
+ } else {
+ printf("error: variable must be single letter\n");
+ }
+ break;
+ case ASSIGNMENT:
+ index = tolower(s[0]) - 'a';
+ val = atof(s+2);
+ if (!assign(index, val)) {
+ printf("error: assignment failed, variable needs to be single letter\n");
+ }
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '-':
+ op2 = pop();
+ push(pop() - op2);
+ break;
+ case '/':
+ op2 = pop();
+ if (op2 != 0.0)
+ push(pop() / op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '%':
+ op2 = pop();
+ if (op2 != 0.0)
+ push((int) pop() % (int) op2);
+ else
+ printf("error: zero divisor\n");
+ break;
+ case '?':
+ printf("\t%.8g\n", printtop());
+ break;
+ case '#':
+ if (duplicate() == 0)
+ printf("error: can't duplicate\n");
+ break;
+ case '~':
+ if (swap() == 0)
+ printf("error: swap failed, stack needs two numbers\n");
+ break;
+ case '!':
+ clear();
+ break;
+ case '\n':
+ printf("\t%.8g\n", pop());
+ break;
+ default:
+ printf("error: unknown command %s\n", s);
+ break;
+ }
+ }
+}
+
+#define MAXVAL 100 /* maximum depth of val stack */
+
+int sp = 0; /* next free stack position */
+double val[MAXVAL]; /* value stack */
+double var[LETTERS]; /* variable stack */
+
+/* push: push f onto value stack */
+void push (double f) {
+ if (sp < MAXVAL)
+ val[sp++] = f;
+ else
+ printf ("error: stack full, can't push %g\n", f);
+}
+
+/* pop: pop and return top value from stack */
+double pop(void) {
+ if (sp > 0)
+ return val[--sp];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* printtop: print the top value of the stack without popping it */
+double printtop(void) {
+ if (sp > 0)
+ return val[sp-1];
+ else {
+ printf("error: stack empty\n");
+ return 0.0;
+ }
+}
+
+/* duplicate: duplicate the top value of the stack
+ * return 1 if successful, 0 on failure */
+int duplicate(void) {
+ if (sp <= 0) {
+ return 0;
+ } else if (sp >= MAXVAL) {
+ return 0;
+ } else {
+ val[sp] = val[sp-1];
+ sp++;
+ return 1;
+ }
+}
+
+/* swap: swap the top two values of the stack
+ * return 1 if successful, 0 on failure */
+int swap(void) {
+ if (sp > 1) {
+ int temp = val[sp-1];
+ val[sp-1] = val[sp-2];
+ val[sp-2] = temp;
+ return 1;
+ }
+ return 0;
+}
+
+/* clear: clear the stack */
+void clear(void) {
+ sp = 0;
+}
+
+/* assign: assign a double to a variable, letters represented by int from 0-25
+ * return 1 on success, 0 on failure */
+int assign(int index, double value) {
+ if (0 <= index && index < LETTERS) {
+ var[index] = value;
+ return 1;
+ }
+ return 0;
+}
+
+/* eval: evaluate variable, letters represented by int from 0-25 */
+double eval(int index) {
+ if (0 <= index && index < LETTERS) {
+ return var[index];
+ }
+ return 0.0;
+}
+
+#include <ctype.h>
+
+int getch(void);
+void ungetch(int);
+
+/* getop: get next operator or numeric operand */
+int getop(char s[]) {
+ int i, c;
+ while ((s[0] = c = getch()) == ' ' || c == '\t')
+ ;
+ s[1] = '\0';
+ i = 0;
+ if (isalpha(c)) {
+ /*
+ while (isalpha(s[++i] = c = getch()))
+ ;
+ */
+ while ((s[++i] = c = getch()) != ' ' && c != '\t' && c != '\n')
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ if (s[1] == '=') {
+ return ASSIGNMENT;
+ } else if (s[1] == '\0') {
+ return VARIABLE;
+ } else {
+ return IDENTIFIER;
+ }
+ }
+ /* negative number or minus */
+ if (c == '-') {
+ s[++i] = c = getch();
+ if (!isdigit(c) && c != '.') {
+ ungetch(c);
+ return '-';
+ }
+ }
+ if (!isdigit(c) && c != '.')
+ return c; /* not a number */
+ if (isdigit(c)) /* collect integer part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ if (c == '.') /* collect fraction part */
+ while (isdigit(s[++i] = c = getch()))
+ ;
+ s[i] = '\0';
+ if (c != EOF)
+ ungetch(c);
+ return NUMBER;
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
blob - /dev/null
blob + d292dbff237c5021e2bb1157de1481a461a3cc1f (mode 644)
--- /dev/null
+++ 4-6.data
+1 2 - 4 5 + *
+-9
+22 7 / 4 3 / + 2 6 + 3 - 9 / -
+3.92063492063492063492
+5 3 % 1 -
+1
+25 7 % 4 * 12 -
+4
+25 7 % 4 * ? 12 -
+16
+4
+-9 -5 -
+-4
+-9 -7 - -3 -
+1
+13 7 * 2 + 15 - 12 ? -
+12
+66
+23 14 - ? 16 4 3 - * ? 2 1 1 + + ? / + 3 %
+9
+16
+4
+1
+23 14 - # * 16 4 3 - * % 2 1 1 + + # * +
+17
+23 14 - # * 16 4 3 - * % 2 1 1 + + # * - 4 /
+-3.75000000000000000000
+4 3 -
+1
+1 !
+23 14 1 3 2 5 1 + + !
+1.571 sin
+1
+3.1415 sin
+0
+1.571 cos
+0
+3.1415 cos
+-1
+1 exp
+2.71828182845904523536
+a=1
+b=2
+c=3
+d=4
+a b c d + / -
+.71428571428571428572
+d c / b a + -
+-1.66667
blob - /dev/null
blob + bde3903b03d1c6bc0c525ee56ad4704dd12ea1d1 (mode 644)
--- /dev/null
+++ 4-7.c
+/*
+ * Exercise 4-7. Write a routine ungets(s) that will push back an entire string
+ * onto the input. Should ungets know about buf and bufp, or should it just use
+ * ungetch?
+ *
+ * Just use ungetch so that the data structure for buf can be changed in
+ * the future
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#define MAXLEN 1000 /* max size of buffer */
+
+int getch(void);
+void ungetch(int);
+void ungets(char []);
+
+int main() {
+ char s[MAXLEN];
+ int i = 0;
+ char c;
+ while ((s[i++] = c = getch()) != EOF) {
+ if (c == '*') {
+ ungets("test");
+ i--;
+ }
+ }
+ s[i] = '\0';
+ printf("%s\n", s);
+}
+
+#define BUFSIZE 100
+
+char buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
+
+void ungets(char s[]) {
+ int i = strlen(s);
+ while (i > 0)
+ ungetch(s[--i]);
+}
blob - /dev/null
blob + 0662600d3c0e2d33cc731e3441d481410a85fff7 (mode 644)
--- /dev/null
+++ 4-7.data
+This is a * of the emergency broadcasting system. It is only a *. If this were a real emergency, you would be notified through this station.
+
+I'm *ing to see if ungets works.
blob - /dev/null
blob + 8619e110e7f237b5cd743215ccebc53c35869be6 (mode 644)
--- /dev/null
+++ 4-8.c
+/*
+ * Exercise 4-8. Suppose that there will never be more than one character of
+ * pushback. Modify getch and ungetch accordingly.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#define MAXLENGTH 800
+
+int getch(void);
+void ungetch(int c);
+
+#define BUFSIZE 100
+
+char buf = EOF; /* buffer for ungetch */
+
+/* get a (possibly pushed back) character, \0 if no character */
+int getch(void) {
+ char c = bufp;
+ bufp = EOF;
+ return c;
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp == EOF)
+ bufp = c;
+ else
+ printf("ungetch: too many characters\n");
+}
blob - /dev/null
blob + 89e95528f04946d4bc270de5492a5112d8cf3a8a (mode 644)
--- /dev/null
+++ 4-9.c
+/*
+ * Exercise 4-9. Our getch and ungetch do not handle a pushed-back EOF
+ * correctly. Decide what their properties ought to be if an EOF is pushed
+ * back, then implement your design.
+ *
+ * EOF is defined as -1, so we need to change the buffer from an array of
+ * chars to an array of ints. The functions are otherwise identical
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#define MAXLEN 1000 /* max size of buffer */
+
+int getch(void);
+void ungetch(int);
+void ungets(char []);
+
+int main() {
+ char s[MAXLEN];
+ int i = 0;
+ char c;
+ while ((s[i++] = c = getch()) != EOF) {
+ if (c == '*') {
+ ungets("test");
+ i--;
+ }
+ }
+ s[i] = '\0';
+ printf("%s\n", s);
+}
+
+#define BUFSIZE 100
+
+int buf[BUFSIZE]; /* buffer for ungetch */
+int bufp = 0;
+
+/* get a (possibly pushed back) character */
+int getch(void) {
+ return (bufp > 0) ? buf[--bufp] : getchar();
+}
+
+/* push character back on input */
+void ungetch(int c) {
+ if (bufp >= BUFSIZE)
+ printf("ungetch: too many characters\n");
+ else
+ buf[bufp++] = c;
+}
+
+void ungets(char s[]) {
+ int i = strlen(s);
+ while (i > 0)
+ ungetch(s[--i]);
+}
blob - /dev/null
blob + dd8ea9ca5e6e497fee8f2dfdd698baffe64f311f (mode 755)
Binary files /dev/null and a.out differ
blob - /dev/null
blob + d96c31c1a2cee0f95dea2153dd1d06d0a2fc842b (mode 644)
Binary files /dev/null and a.out.core differ
blob - /dev/null
blob + 129cdf895914f4d4803456165862bea0360a9933 (mode 644)
--- /dev/null
+++ alice.txt
+CHAPTER I.
+Down the Rabbit-Hole
+
+https://wordpress.org/support/topic/how-to-remove-extremely-long-url-in-search-console-results/blahblahblah/moreblah
+
+
+
+Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice "without pictures or conversations?" So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.
+ There was nothing so _very_ remarkable in that; nor did Alice think it so _very_ much out of the way to hear the Rabbit say to itself, "Oh dear! Oh dear! I shall be late!" (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually _took a watch out of its waistcoat-pocket_, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.
+ In another moment down went Alice after it, never once considering how in the world she was to get out again. The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled
+"ORANGE MARMALADE", but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody underneath, so managed to put it into one of the cupboards as she fell past it. "Well!" thought Alice to herself, "after such a fall as this, I shall think nothing of tumbling down stairs! How brave they'll all think me at home! Why, I wouldn't say anything about it, even if I fell off the top of the house!" (Which was very likely true.) Down, down, down. Would the fall _never_ come to an end? "I wonder how many miles I've fallen by this time?" she said aloud.
+"I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down, I think-" (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a _very_ good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) "-yes, that's about the right distance-but then I wonder what Latitude or Longitude I've got to?" (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say.) Presently she began again. "I wonder if I shall fall right _through_ the earth! How funny it'll seem to come out among the people that walk with their heads downward!
+The Antipathies, I think-" (she was rather glad there _was_ no one listening, this time, as it didn't sound at all the right word) "-but I shall have to ask them what the name of the country is, you know. Please, Ma'am, is this New Zealand or Australia?" (and she tried to curtsey as she spoke-fancy _curtseying_ as you're falling through the air! Do you think you could manage it?) "And what an ignorant little girl she'll think me for asking! No, it'll never do to ask: perhaps I shall see it written up somewhere." Down, down, down. There was nothing else to do, so Alice soon began talking again. "Dinah'll miss me very much to-night, I should think!" (Dinah was the cat.)
+"I hope they'll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I'm afraid, but you might catch a bat, and that's very like a mouse, you know. But do cats eat bats, I wonder?" And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, "Do cats eat bats? Do cats eat bats?" and sometimes, "Do bats eat cats?" for, you see, as she couldn't answer either question, it didn't much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, "Now, Dinah, tell me the truth: did you ever eat a bat?" when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over.
+Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, "Oh my ears and whiskers, how late it's getting!" She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof. There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again.
+Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted! Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head through the doorway; "and even if my head would go through," thought poor Alice, "it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only knew how to begin." For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible. There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, ("which certainly was not here before," said Alice,) and round the neck of the bottle was a paper label, with the words "DRINK ME," beautifully printed on it in large letters. It was all very well to say "Drink me," but the wise little Alice was not going to do _that_ in a hurry. "No, I'll look first," she said, "and see whether it's marked ‘_poison_' or not"; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they _would_ not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger _very_ deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked "poison," it is almost certain to disagree with you, sooner or later. However, this bottle was _not_ marked "poison," so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off. * * * * * * * * * * * * * * * * * * * * "What a curious feeling!" said Alice; "I must be shutting up like a telescope." And so it was indeed: she was now only ten inches high, and her face brightened up at the thought that she was now the right size for going through the little door into that lovely garden. First, however, she waited for a few minutes to see if she was going to shrink any further: she felt a little nervous about this; "for it might end, you know," said Alice to herself, "in my going out altogether, like a candle. I wonder what I should be like then?" And she tried to fancy what the flame of a candle is like after the candle is blown out, for she could not remember ever having seen such a thing. After a while, finding that nothing more happened, she decided on going into the garden at once; but, alas for poor Alice! when she got to the door, she found she had forgotten the little golden key, and when she went back to the table for it, she found she could not possibly reach it: she could see it quite plainly through the glass, and she tried her best to climb up one of the legs of the table, but it was too slippery; and when she had tired herself out with trying, the poor little thing sat down and cried. "Come, there's no use in crying like that!" said Alice to herself, rather sharply; "I advise you to leave off this minute!" She generally gave herself very good advice, (though she very seldom followed it), and sometimes she scolded herself so severely as to bring tears into her eyes; and once she remembered trying to box her own ears for having cheated herself in a game of croquet she was playing against herself, for this curious child was very fond of pretending to be two people. "But it's no use now," thought poor Alice, "to pretend to be two people! Why, there's hardly enough of me left to make _one_ respectable person!" Soon her eye fell on a little glass box that was lying under the table: she opened it, and found in it a very small cake, on which the words "EAT ME" were beautifully marked in currants. "Well, I'll eat it," said Alice, "and if it makes me grow larger, I can reach the key; and if it makes me grow smaller, I can creep under the door; so either way I'll get into the garden, and I don't care which happens!" She ate a little bit, and said anxiously to herself, "Which way? Which way?", holding her hand on the top of her head to feel which way it was growing, and she was quite surprised to find that she remained the same size: to be sure, this generally happens when one eats cake, but Alice had got so much into the way of expecting nothing but out-of-the-way things to happen, that it seemed quite dull and stupid for life to go on in the common way. So she set to work, and very soon finished off the cake. * * * * * * * * * * * * * * * * * * * * CHAPTER II. The Pool of Tears "Curiouser and curiouser!" cried Alice (she was so much surprised, that for the moment she quite forgot how to speak good English); "now I'm opening out like the largest telescope that ever was! Good-bye, feet!" (for when she looked down at her feet, they seemed to be almost out of sight, they were getting so far off). "Oh, my poor little feet, I wonder who will put on your shoes and stockings for you now, dears? I'm sure _I_ shan't be able! I shall be a great deal too far off to trouble myself about you: you must manage the best way you can;-but I must be kind to them," thought Alice, "or perhaps they won't walk the way I want to go! Let me see: I'll give them a new pair of boots every Christmas." And she went on planning to herself how she would manage it. "They must go by the carrier," she thought; "and how funny it'll seem, sending presents to one's own feet! And how odd the directions will look! _Alice's Right Foot, Esq., Hearthrug, near the Fender,_ (_with Alice's love_). Oh dear, what nonsense I'm talking!" Just then her head struck against the roof of the hall: in fact she was now more than nine feet high, and she at once took up the little golden key and hurried off to the garden door. Poor Alice! It was as much as she could do, lying down on one side, to look through into the garden with one eye; but to get through was more hopeless than ever: she sat down and began to cry again. "You ought to be ashamed of yourself," said Alice, "a great girl like you," (she might well say this), "to go on crying in this way! Stop this moment, I tell you!" But she went on all the same, shedding gallons of tears, until there was a large pool all round her, about four inches deep and reaching half down the hall. After a time she heard a little pattering of feet in the distance, and she hastily dried her eyes to see what was coming. It was the White Rabbit returning, splendidly dressed, with a pair of white kid gloves in one hand and a large fan in the other: he came trotting along in a great hurry, muttering to himself as he came, "Oh! the Duchess, the Duchess! Oh! won't she be savage if I've kept her waiting!" Alice felt so desperate that she was ready to ask help of any one; so, when the Rabbit came near her, she began, in a low, timid voice, "If you please, sir-" The Rabbit started violently, dropped the white kid gloves and the fan, and skurried away into the darkness as hard as he could go. Alice took up the fan and gloves, and, as the hall was very hot, she kept fanning herself all the time she went on talking: "Dear, dear! How queer everything is to-day! And yesterday things went on just as usual. I wonder if I've been changed in the night? Let me think: was I the same when I got up this morning? I almost think I can remember feeling a little different. But if I'm not the same, the next question is, Who in the world am I? Ah, _that's_ the great puzzle!" And she began thinking over all the children she knew that were of the same age as herself, to see if she could have been changed for any of them. "I'm sure I'm not Ada," she said, "for her hair goes in such long ringlets, and mine doesn't go in ringlets at all; and I'm sure I can't be Mabel, for I know all sorts of things, and she, oh! she knows such a very little! Besides, _she's_ she, and _I'm_ I, and-oh dear, how puzzling it all is! I'll try if I know all the things I used to know. Let me see: four times five is twelve, and four times six is thirteen, and four times seven is-oh dear! I shall never get to twenty at that rate! However, the Multiplication Table doesn't signify: let's try Geography. London is the capital of Paris, and Paris is the capital of Rome, and Rome-no, _that's_ all wrong, I'm certain! I must have been changed for Mabel! I'll try and say ‘_How doth the little_-'" and she crossed her hands on her lap as if she were saying lessons, and began to repeat it, but her voice sounded hoarse and strange, and the words did not come the same as they used to do:- "How doth the little crocodile Improve his shining tail, And pour the waters of the Nile On every golden scale! "How cheerfully he seems to grin, How neatly spread his claws, And welcome little fishes in With gently smiling jaws!" "I'm sure those are not the right words," said poor Alice, and her eyes filled with tears again as she went on, "I must be Mabel after all, and I shall have to go and live in that poky little house, and have next to no toys to play with, and oh! ever so many lessons to learn! No, I've made up my mind about it; if I'm Mabel, I'll stay down here! It'll be no use their putting their heads down and saying ‘Come up again, dear!' I shall only look up and say ‘Who am I then? Tell me that first, and then, if I like being that person, I'll come up: if not, I'll stay down here till I'm somebody else'-but, oh dear!" cried Alice, with a sudden burst of tears, "I do wish they _would_ put their heads down! I am so _very_ tired of being all alone here!" As she said this she looked down at her hands, and was surprised to see that she had put on one of the Rabbit's little white kid gloves while she was talking. "How _can_ I have done that?" she thought. "I must be growing small again." She got up and went to the table to measure herself by it, and found that, as nearly as she could guess, she was now about two feet high, and was going on shrinking rapidly: she soon found out that the cause of this was the fan she was holding, and she dropped it hastily, just in time to avoid shrinking away altogether. "That _was_ a narrow escape!" said Alice, a good deal frightened at the sudden change, but very glad to find herself still in existence; "and now for the garden!" and she ran with all speed back to the little door: but, alas! the little door was shut again, and the little golden key was lying on the glass table as before, "and things are worse than ever," thought the poor child, "for I never was so small as this before, never! And I declare it's too bad, that it is!" As she said these words her foot slipped, and in another moment, splash! she was up to her chin in salt water. Her first idea was that she had somehow fallen into the sea, "and in that case I can go back by railway," she said to herself. (Alice had been to the seaside once in her life, and had come to the general conclusion, that wherever you go to on the English coast you find a number of bathing machines in the sea, some children digging in the sand with wooden spades, then a row of lodging houses, and behind them a railway station.) However, she soon made out that she was in the pool of tears which she had wept when she was nine feet high. "I wish I hadn't cried so much!" said Alice, as she swam about, trying to find her way out. "I shall be punished for it now, I suppose, by being drowned in my own tears! That _will_ be a queer thing, to be sure! However, everything is queer to-day." Just then she heard something splashing about in the pool a little way off, and she swam nearer to make out what it was: at first she thought it must be a walrus or hippopotamus, but then she remembered how small she was now, and she soon made out that it was only a mouse that had slipped in like herself. "Would it be of any use, now," thought Alice, "to speak to this mouse? Everything is so out-of-the-way down here, that I should think very likely it can talk: at any rate, there's no harm in trying." So she began: "O Mouse, do you know the way out of this pool? I am very tired of swimming about here, O Mouse!" (Alice thought this must be the right way of speaking to a mouse: she had never done such a thing before, but she remembered having seen in her brother's Latin Grammar, "A mouse-of a mouse-to a mouse-a mouse-O mouse!") The Mouse looked at her rather inquisitively, and seemed to her to wink with one of its little eyes, but it said nothing. "Perhaps it doesn't understand English," thought Alice; "I daresay it's a French mouse, come over with William the Conqueror." (For, with all her knowledge of history, Alice had no very clear notion how long ago anything had happened.) So she began again: "Où est ma chatte?" which was the first sentence in her French lesson-book. The Mouse gave a sudden leap out of the water, and seemed to quiver all over with fright. "Oh, I beg your pardon!" cried Alice hastily, afraid that she had hurt the poor animal's feelings. "I quite forgot you didn't like cats." "Not like cats!" cried the Mouse, in a shrill, passionate voice. "Would _you_ like cats if you were me?" "Well, perhaps not," said Alice in a soothing tone: "don't be angry about it. And yet I wish I could show you our cat Dinah: I think you'd take a fancy to cats if you could only see her. She is such a dear quiet thing," Alice went on, half to herself, as she swam lazily about in the pool, "and she sits purring so nicely by the fire, licking her paws and washing her face-and she is such a nice soft thing to nurse-and she's such a capital one for catching mice-oh, I beg your pardon!" cried Alice again, for this time the Mouse was bristling all over, and she felt certain it must be really offended. "We won't talk about her any more if you'd rather not." "We indeed!" cried the Mouse, who was trembling down to the end of his tail. "As if _I_ would talk on such a subject! Our family always _hated_ cats: nasty, low, vulgar things! Don't let me hear the name again!" "I won't indeed!" said Alice, in a great hurry to change the subject of conversation. "Are you-are you fond-of-of dogs?" The Mouse did not answer, so Alice went on eagerly: "There is such a nice little dog near our house I should like to show you! A little bright-eyed terrier, you know, with oh, such long curly brown hair! And it'll fetch things when you throw them, and it'll sit up and beg for its dinner, and all sorts of things-I can't remember half of them-and it belongs to a farmer, you know, and he says it's so useful, it's worth a hundred pounds! He says it kills all the rats and-oh dear!" cried Alice in a sorrowful tone, "I'm afraid I've offended it again!" For the Mouse was swimming away from her as hard as it could go, and making quite a commotion in the pool as it went. So she called softly after it, "Mouse dear! Do come back again, and we won't talk about cats or dogs either, if you don't like them!" When the Mouse heard this, it turned round and swam slowly back to her: its face was quite pale (with passion, Alice thought), and it said in a low trembling voice, "Let us get to the shore, and then I'll tell you my history, and you'll understand why it is I hate cats and dogs." It was high time to go, for the pool was getting quite crowded with the birds and animals that had fallen into it: there were a Duck and a Dodo, a Lory and an Eaglet, and several other curious creatures. Alice led the way, and the whole party swam to the shore. CHAPTER III. A Caucus-Race and a Long Tale
blob - /dev/null
blob + 45bcadd575e9f1cfdffe501a86e60d4ededa80c1 (mode 644)
--- /dev/null
+++ alice2.txt
+CHAPTER I.
+Down the Rabbit-Hole
+
+https://wordpress.org/support/topic/how-to-remove-extremely-long-url-in-search-c
+onsole-results/blahblahblah/moreblah
+
+
+
+Alice was beginning to get very tired of sitting
+by her sister on
+the bank, and of having nothing to do:
+ once or twice she had peeped into the book her sister w
+as reading, but it had no pictures or conversations in it, "and what is the use
+of a book," thought Alice "without pictures or conversations?" So she was consid
+ering in her own mind (as well as she could, for the hot day made her feel very
+sleepy and stupid), whether the pleasure of making a daisy-chain would be worth
+the trouble of getting up and picking the daisies, when suddenly a White Rabbit
+with pink eyes ran close by her.
+ There was nothing so _very_ rem
+arkable in that; nor did Alice think it so _very_ much out of the way to hear th
+e Rabbit say to itself, "Oh dear! Oh dear! I shall be late!" (when she thought i
+t over afterwards, it occurred to her that she ought to have wondered at this, b
+ut at the time it all seemed quite natural);
+ but when the Rabbit actually _took a watch out of its waistcoat-pocket_
+, and looked at it, and then hurri
+ed on, Alice started to her feet, for it flashed across her mind that she had ne
+ver before seen a rabbit with either a waistcoat-pocket, or a watch to take out
+of it, and burning with curiosity, she ran across the field after it,
+and fortunately was just in time
+to see it pop down a large rabbit-hole under the hedge.
+ In another moment down went Alice after it, never
+ once considering how in the world she was to get o
+ut again. The rabbit-hole went straight on like a tunnel for some way, and
+then dipped suddenly down, so suddenly that Alice had not a moment to think abou
+t stopping herself before she found herself falling down a very deep well. Eith
+er the well was very deep, or she fell very slowly, for she had plenty of time a
+s she went down to look about her and to wonder what was going to happen next. F
+irst, she tried to look down and make out what she was coming to, but it was
+too dark to see anything; then she looked at the sides of the well, and noticed
+that they were filled with cupboards and book-shelves; here and there she saw ma
+ps and pictures hung upon pegs. She took down a jar from one of the shelves as s
+he passed; it was labelled
+"ORANGE MARMALADE", but to her great disappointment it was empty: she did not li
+ke to drop the jar for fear of killing somebody underneath, so managed to put
+it into one of the cupboards as she fell past it. "Well!" thought Alice to hers
+elf, "after such a fall as this, I shall think nothing of tumbling down stairs!
+How brave they'll all think me at home! Why, I wouldn't say anything about it, e
+ven if I fell off the top of the house!" (Which was very likely true.) Down, dow
+n, down. Would the fall _never_ come to an end? "I wonder how many miles I've fa
+llen by this time?" she said aloud.
+"I must be getting somewhere near the centre of the earth. Let me see: that woul
+d be four thousand miles down, I think-" (for, you see, Alice had learnt
+several things of this sort in her lessons in the schoolroom, and though this wa
+s not a _very_ good opportunity for showing off her knowledge, as there was no o
+ne to listen to her, still it was good practice to say it over) "-yes, that's ab
+out the right distance-but then I wonder what Latitude or Longitude I've got to?
+" (Alice had no idea what Latitude was, or Longitude either, but thought they we
+re nice grand words to say.) Presently she began again. "I wonder if I shall fal
+l right _through_ the earth! How funny it'll seem to come out among the people t
+hat walk with their heads downward!
+The Antipathies, I think-" (she was rather glad there _was_ no one listening, th
+is time, as it didn't sound at all the right word) "-but I shall have to ask the
+m what the name of the country is, you know. Please, Ma'am, is this New Zealand
+or Australia?" (and she tried to curtsey as she spoke-fancy _curtseying_ as you'
+re falling through the air! Do you think you could manage it?) "And what an igno
+rant little girl she'll think me for asking! No, it'll never do to ask: perhaps
+I shall see it written up somewhere." Down, down, down. There was nothing else t
+o do, so Alice soon began talking again. "Dinah'll miss me very much to-night,
+I should think!" (Dinah was the cat.)
+"I hope they'll remember her saucer of milk at tea-time. Dinah my dear! I wish y
+ou were down here with me! There are no mice in the air, I'm afraid, but you mig
+ht catch a bat, and that's very like a mouse, you know. But do cats eat bats, I
+wonder?" And here Alice began to get rather sleepy, and went on saying to hersel
+f, in a dreamy sort of way, "Do cats eat bats? Do cats eat bats?" and
+sometimes, "Do bats eat cats?" for, you see, as she couldn't answer either quest
+ion, it didn't much matter which way she put it. She felt that she was dozing of
+f, and had just begun to dream that she was walking hand in hand with Dinah,
+and saying to her very earnestly, "Now, Dinah, tell me the truth: did you ever e
+at a bat?" when suddenly, thump! thump! down she came upon a heap of sticks and
+dry leaves, and the fall was over.
+Alice was not a bit hurt, and she jumped up on to her feet in a moment: she look
+ed up, but it was all dark overhead; before her was another long passage, and th
+e White Rabbit was still in sight, hurrying down it. There was not a moment to b
+e lost: away went Alice like the wind, and was just in time to hear it say, as i
+t turned a corner, "Oh my ears and whiskers, how late it's getting!" She was clo
+se behind it when she turned the corner, but the Rabbit was no longer to be seen
+: she found herself in a long, low hall, which was lit up by a row of lamps hang
+ing from the roof. There were doors all round the hall, but they were all locke
+d; and when Alice had been all the way down one side and up the other, trying ev
+ery door, she walked sadly down the middle, wondering how she was ever to get ou
+t again.
+Suddenly she came upon a little three-legged table, all made of solid glass; the
+re was nothing on it except a tiny golden key, and Alice's first thought was tha
+t it might belong to one of the doors of the hall; but, alas! either the locks w
+ere too large, or the key was too small, but at any rate it would not open any o
+f them. However, on the second time round, she came upon a low curtain she had n
+ot noticed before, and behind it was a little door about fifteen inches high: sh
+e tried the little golden key in the lock, and to her great delight it fitted!
+Alice opened the door and found that it led into a small passage, not much large
+r than a rat-hole: she knelt down and looked along the passage into the lovelies
+t garden you ever saw. How she longed to get out of that dark hall, and wander a
+bout among those beds of bright flowers and those cool fountains, but she could
+not even get her head through the doorway; "and even if my head would go through
+," thought poor Alice, "it would be of very little use without my shoulders.
+Oh, how I wish I could shut up like a telescope! I think I could, if I only
+knew how to begin." For, you see, so many out-of-the-way things had happened lat
+ely, that Alice had begun to think that very few things indeed were really impos
+sible. There seemed to be no use in waiting by the little door, so she went bac
+k to the table, half hoping she might find another key on it, or at any rate a b
+ook of rules for shutting people up like telescopes: this time she found a littl
+e bottle on it, ("which certainly was not here before," said Alice,) and round t
+he neck of the bottle was a paper label, with the words "DRINK ME," beautifully
+printed on it in large letters. It was all very well to say "Drink me," but
+the wise little Alice was not going to do _that_ in a hurry. "No, I'll look firs
+t," she said, "and see whether it's marked ‘_poison_' or not"; for she had rea
+d several nice little histories about children who had got burnt, and eaten up b
+y wild beasts and other unpleasant things, all because they _would_ not
+remember the simple rules their friends had taught them: such as, that a
+red-hot poker will burn you if you hold it too long; and that if you cut your fi
+nger _very_ deeply with a knife, it usually bleeds; and she had never forgotten
+that, if you drink much from a bottle marked "poison," it is almost certain to d
+isagree with you, sooner or later. However, this bottle was _not_ marked "poiso
+n," so Alice ventured to taste it, and finding it very nice, (it had, in fact,
+a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffe
+e, and hot buttered toast,) she very soon finished it off. * * *
+ * * * * * * * * * * * * *
+ * * * * "What a curious feeling!" said Alice; "I must be shutti
+ng up like a telescope." And so it was indeed: she was now only ten inches
+high, and her face brightened up at the thought that she was now the right size
+for going through the little door into that lovely garden. First, however, she w
+aited for a few minutes to see if she was going to shrink any further: she felt
+a little nervous about this; "for it might end, you know," said Alice to herself
+, "in my going out altogether, like a candle. I wonder what I should be like the
+n?" And she tried to fancy what the flame of a candle is like after the candle i
+s blown out, for she could not remember ever having seen such a thing. After a
+while, finding that nothing more happened, she decided on going into the garden
+at once; but, alas for poor Alice! when she got to the door, she found she had f
+orgotten the little golden key, and when she went back to the table for it, she
+found she could not possibly reach it: she could see it quite plainly through th
+e glass, and she tried her best to climb up one of the legs of the table, but
+it was too slippery; and when she had tired herself out with trying, the poor li
+ttle thing sat down and cried. "Come, there's no use in crying like that!"
+said Alice to herself, rather sharply; "I advise you to leave off this minute!"
+She generally gave herself very good advice, (though she very seldom followed it
+), and sometimes she scolded herself so severely as to bring tears into her eyes
+; and once she remembered trying to box her own ears for having cheated herself
+in a game of croquet she was playing against herself, for this curious child
+was very fond of pretending to be two people. "But it's no use now," thought po
+or Alice, "to pretend to be two people! Why, there's hardly enough of me left
+to make _one_ respectable person!" Soon her eye fell on a little glass box that
+was lying under the table: she opened it, and found in it a very small cake, on
+which the words "EAT ME" were beautifully marked in currants. "Well, I'll eat it
+," said Alice, "and if it makes me grow larger, I can reach the key; and if it m
+akes me grow smaller, I can creep under the door; so either way I'll get into th
+e garden, and I don't care which happens!" She ate a little bit, and said anxiou
+sly to herself, "Which way? Which way?", holding her hand on the top of her
+head to feel which way it was growing, and she was quite surprised to find that
+she remained the same size: to be sure, this generally happens when one eats cak
+e, but Alice had got so much into the way of expecting nothing but out-of-the-wa
+y things to happen, that it seemed quite dull and stupid for life to go on in th
+e common way. So she set to work, and very soon finished off the cake. *
+* * * * * * * * * * * * *
+ * * * * * * CHAPTER II. The Pool of Tears "Curiouser
+and curiouser!" cried Alice (she was so much surprised, that for the moment she
+quite forgot how to speak good English); "now I'm opening out like the largest t
+elescope that ever was! Good-bye, feet!" (for when she looked down at her feet,
+they seemed to be almost out of sight, they were getting so far off). "Oh, my po
+or little feet, I wonder who will put on your shoes and stockings for you now, d
+ears? I'm sure _I_ shan't be able! I shall be a great deal too far off to troubl
+e myself about you: you must manage the best way you can;-but I must be kind to
+them," thought Alice, "or perhaps they won't walk the way I want to go! Let me s
+ee: I'll give them a new pair of boots every Christmas." And she went on plannin
+g to herself how she would manage it. "They must go by the carrier," she thought
+; "and how funny it'll seem, sending presents to one's own feet! And how odd
+the directions will look! _Alice's Right Foot, Esq., Hearthrug, near the Fender
+,_ (_with Alice's love_). Oh dear, what nonsense I'm talking!" Just then her he
+ad struck against the roof of the hall: in fact she was now more than nine feet
+high, and she at once took up the little golden key and hurried off to the garde
+n door. Poor Alice! It was as much as she could do, lying down on one side, to
+look through into the garden with one eye; but to get through was more hopeless
+than ever: she sat down and began to cry again. "You ought to be ashamed of you
+rself," said Alice, "a great girl like you," (she might well say this), "to go o
+n crying in this way! Stop this moment, I tell you!" But she went on all the sam
+e, shedding gallons of tears, until there was a large pool all round her, about
+four inches deep and reaching half down the hall. After a time she heard a litt
+le pattering of feet in the distance, and she hastily dried her eyes to see
+what was coming. It was the White Rabbit returning, splendidly dressed, with a p
+air of white kid gloves in one hand and a large fan in the other: he came trotti
+ng along in a great hurry, muttering to himself as he came, "Oh! the Duchess, th
+e Duchess! Oh! won't she be savage if I've kept her waiting!" Alice felt so desp
+erate that she was ready to ask help of any one; so, when the Rabbit came near h
+er, she began, in a low, timid voice, "If you please, sir-" The Rabbit started v
+iolently, dropped the white kid gloves and the fan, and skurried away into the d
+arkness as hard as he could go. Alice took up the fan and gloves, and, as the h
+all was very hot, she kept fanning herself all the time she went on talking: "De
+ar, dear! How queer everything is to-day! And yesterday things went on just as u
+sual. I wonder if I've been changed in the night? Let me think: was I the same
+when I got up this morning? I almost think I can remember feeling a little diffe
+rent. But if I'm not the same, the next question is, Who in the world am I? Ah,
+_that's_ the great puzzle!" And she began thinking over all the children she kne
+w that were of the same age as herself, to see if she could have been changed fo
+r any of them. "I'm sure I'm not Ada," she said, "for her hair goes in such lon
+g ringlets, and mine doesn't go in ringlets at all; and I'm sure I can't be Mabe
+l, for I know all sorts of things, and she, oh! she knows such a very little! Be
+sides, _she's_ she, and _I'm_ I, and-oh dear, how puzzling it all is! I'll try i
+f I know all the things I used to know. Let me see: four times five is twelve,
+and four times six is thirteen, and four times seven is-oh dear! I shall never g
+et to twenty at that rate! However, the Multiplication Table doesn't signify: le
+t's try Geography. London is the capital of Paris, and Paris is the capital of R
+ome, and Rome-no, _that's_ all wrong, I'm certain! I must have been changed for
+Mabel! I'll try and say ‘_How doth the little_-'" and she crossed her hands
+on her lap as if she were saying lessons, and began to repeat it, but her voice
+sounded hoarse and strange, and the words did not come the same as they used to
+do:- "How doth the little crocodile Improve his shining tail, And pour the water
+s of the Nile On every golden scale! "How cheerfully he seems to grin, How neat
+ly spread his claws, And welcome little fishes in With gently smiling jaws!" "I'
+m sure those are not the right words," said poor Alice, and her eyes filled
+with tears again as she went on, "I must be Mabel after all, and I shall have
+to go and live in that poky little house, and have next to no toys to play
+with, and oh! ever so many lessons to learn! No, I've made up my mind about it;
+if I'm Mabel, I'll stay down here! It'll be no use their putting their heads dow
+n and saying ‘Come up again, dear!' I shall only look up and say ‘Who am I t
+hen? Tell me that first, and then, if I like being that person, I'll come up:
+if not, I'll stay down here till I'm somebody else'-but, oh dear!" cried Alice,
+with a sudden burst of tears, "I do wish they _would_ put their heads down! I
+am so _very_ tired of being all alone here!" As she said this she looked down
+at her hands, and was surprised to see that she had put on one of the Rabbit's l
+ittle white kid gloves while she was talking. "How _can_ I have done that?" she
+thought. "I must be growing small again." She got up and went to the table to me
+asure herself by it, and found that, as nearly as she could guess, she was now a
+bout two feet high, and was going on shrinking rapidly: she soon found out that
+the cause of this was the fan she was holding, and she dropped it hastily, just
+in time to avoid shrinking away altogether. "That _was_ a narrow escape!" said
+Alice, a good deal frightened at the sudden change, but very glad to find hersel
+f still in existence; "and now for the garden!" and she ran with all speed back
+to the little door: but, alas! the little door was shut again, and the little go
+lden key was lying on the glass table as before, "and things are worse than ever
+," thought the poor child, "for I never was so small as this before, never! And
+I declare it's too bad, that it is!" As she said these words her foot slipped, a
+nd in another moment, splash! she was up to her chin in salt water. Her first id
+ea was that she had somehow fallen into the sea, "and in that case I can go
+back by railway," she said to herself. (Alice had been to the seaside once in he
+r life, and had come to the general conclusion, that wherever you go to on the E
+nglish coast you find a number of bathing machines in the sea, some children dig
+ging in the sand with wooden spades, then a row of lodging houses, and behind th
+em a railway station.) However, she soon made out that she was in the pool of te
+ars which she had wept when she was nine feet high. "I wish I hadn't cried so m
+uch!" said Alice, as she swam about, trying to find her way out. "I shall be pun
+ished for it now, I suppose, by being drowned in my own tears! That _will_ be a
+queer thing, to be sure! However, everything is queer to-day." Just then she hea
+rd something splashing about in the pool a little way off, and she swam nearer t
+o make out what it was: at first she thought it must be a walrus or hippopotamus
+, but then she remembered how small she was now, and she soon made out that it w
+as only a mouse that had slipped in like herself. "Would it be of any use, now,
+" thought Alice, "to speak to this mouse? Everything is so out-of-the-way down
+here, that I should think very likely it can talk: at any rate, there's no harm
+in trying." So she began: "O Mouse, do you know the way out of this pool? I am v
+ery tired of swimming about here, O Mouse!" (Alice thought this must be the righ
+t way of speaking to a mouse: she had never done such a thing before, but she re
+membered having seen in her brother's Latin Grammar, "A mouse-of a mouse-to a mo
+use-a mouse-O mouse!") The Mouse looked at her rather inquisitively, and seemed
+to her to wink with one of its little eyes, but it said nothing. "Perhaps it do
+esn't understand English," thought Alice; "I daresay it's a French mouse, come o
+ver with William the Conqueror." (For, with all her knowledge of history, Alice
+had no very clear notion how long ago anything had happened.) So she began again
+: "Où est ma chatte?" which was the first sentence in her French lesson-book. T
+he Mouse gave a sudden leap out of the water, and seemed to quiver all over
+with fright. "Oh, I beg your pardon!" cried Alice hastily, afraid that she had h
+urt the poor animal's feelings. "I quite forgot you didn't like cats." "Not
+like cats!" cried the Mouse, in a shrill, passionate voice. "Would _you_ like ca
+ts if you were me?" "Well, perhaps not," said Alice in a soothing tone: "don't b
+e angry about it. And yet I wish I could show you our cat Dinah: I think you'd t
+ake a fancy to cats if you could only see her. She is such a dear quiet thing,"
+Alice went on, half to herself, as she swam lazily about in the pool, "and she s
+its purring so nicely by the fire, licking her paws and washing her face-and
+she is such a nice soft thing to nurse-and she's such a capital one for
+catching mice-oh, I beg your pardon!" cried Alice again, for this time the
+Mouse was bristling all over, and she felt certain it must be really offended. "
+We won't talk about her any more if you'd rather not." "We indeed!" cried the Mo
+use, who was trembling down to the end of his tail. "As if _I_ would talk on suc
+h a subject! Our family always _hated_ cats: nasty, low, vulgar things! Don't le
+t me hear the name again!" "I won't indeed!" said Alice, in a great hurry to cha
+nge the subject of conversation. "Are you-are you fond-of-of dogs?" The Mouse di
+d not answer, so Alice went on eagerly: "There is such a nice little dog near ou
+r house I should like to show you! A little bright-eyed terrier, you know, with
+oh, such long curly brown hair! And it'll fetch things when you throw them, and
+it'll sit up and beg for its dinner, and all sorts of things-I can't remember ha
+lf of them-and it belongs to a farmer, you know, and he says it's so useful, it'
+s worth a hundred pounds! He says it kills all the rats and-oh dear!" cried Alic
+e in a sorrowful tone, "I'm afraid I've offended it again!" For the Mouse was sw
+imming away from her as hard as it could go, and making quite a commotion in
+the pool as it went. So she called softly after it, "Mouse dear! Do come back a
+gain, and we won't talk about cats or dogs either, if you don't like them!"
+When the Mouse heard this, it turned round and swam slowly back to her: its
+face was quite pale (with passion, Alice thought), and it said in a low tremblin
+g voice, "Let us get to the shore, and then I'll tell you my history, and
+you'll understand why it is I hate cats and dogs." It was high time to go, for t
+he pool was getting quite crowded with the birds and animals that had fallen int
+o it: there were a Duck and a Dodo, a Lory and an Eaglet, and several other curi
+ous creatures. Alice led the way, and the whole party swam to the shore. CHAPTE
+R III. A Caucus-Race and a Long Tale
blob - /dev/null
blob + e678d8f57fdece274e6c82edcfa10e10195ec92d (mode 644)
--- /dev/null
+++ fahr.c
+#include <stdio.h>
+
+/* print Fahrenheit-Celsius table
+ for fahr = 0, 20, ..., 300 */
+main() {
+ int fahr, celsius;
+ int lower, upper, step;
+
+ lower = 0; /* lower limit of temperature table */
+ upper = 300; /* upper limit */
+ step = 20; /* step size */
+
+ fahr = lower;
+ while (fahr <= upper) {
+ celsius = 5 * (fahr-32) / 9;
+ printf("%d\t%d\n", fahr, celsius);
+ fahr = fahr + step;
+ }
+}
blob - /dev/null
blob + f050499d4d0a138d7dd76f6adb19d1bb619a8a16 (mode 644)
--- /dev/null
+++ fahrfloat.c
+#include <stdio.h>
+
+/* print Fahrenheit-Celsius table
+ for fahr = 0, 20, ..., 300; floating-point version */
+
+main()
+{
+ float fahr, celsius;
+ int lower, upper, step;
+
+ lower = 0; /* lower limit of temperature table */
+ upper = 300; /* upper limit */
+ step = 20; /* step size */
+
+ fahr = lower;
+ while (fahr <= upper) {
+ celsius = (5.0/9.0) * (fahr - 32.0);
+ printf("%3.0f %6.1f\n", fahr, celsius);
+ fahr = fahr + step;
+ }
+}
blob - /dev/null
blob + 3fc68494b2464de132f2a9a96a8558c1df079e7c (mode 644)
--- /dev/null
+++ hello.c
+#include <stdio.h>
+
+main() {
+ printf("hello, world\n");
+}
blob - /dev/null
blob + 20c9892599b66aeeb23e6a00ce92bf665ce718ee (mode 644)
--- /dev/null
+++ loremipsum
+Part 1:
+Where do you usually get your news?
+Do you follow the news regularly?
+What type of news do you like to read?
+How do your peers normally get the news?
+Do you think journalism is important?
+
+How often do you use computers?
+What types of computers do you use most often?
+What do you use computers for?
+Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television?
+What types of programs do you watch?
+What shows do your friends like to watch?
+Do you think television is beneficial or harmful for society?
+
+Do you take public transportation?
+What are some advantages of public transportation?
+Do many people in your country use public transit?
+Why don't more people use public transit?
+What could be improved about it?
+
+Do you enjoy outdoor activities?
+What types of outdoor activities do you do?
+How much time do you spend outdoors each week?
+What are some popular outdoor activities in your country?
+
+How long do you sleep for each day?
+Do you get enough sleep each night?
+How many hours of sleep does a person need to be healthy?
+How can someone improve their sleeping pattern?
+Do people need more sleep as they get older?
+
+How would you describe your ideal job?
+Why would you like this ideal job?
+Are you taking any steps to reach this goal?
+Is it important for each person to find his ideal job?
blob - /dev/null
blob + adbb576967af36f0c3e9cd2223727a55aef491fe (mode 644)
--- /dev/null
+++ loremipsum2
+hi there friend of mine
blob - /dev/null
blob + 8c9e243e6035c2ca540734613af5ec0701d6e2e9 (mode 644)
--- /dev/null
+++ loremipsum3
+Part 1:
+Where do you usually get your news?
+Do you follow the news regularly?
+What type of news do you like to read?
+How do your peers normally get the news?
+Do you think journalism is important?
+
+How often do you use computers?
+What types of computers do you use most often?
+What do you use computers for?
+Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television?
+What types of programs do you watch?
+What shows do your friends like to watch?
+Do you think television is beneficial or harmful for society?
+
+Do you take public transportation?
+What are some advantages of public transportation?
+Do many people in your country use public transit?
+Why don't more people use public transit?
+What could be improved about it?
+
+
+
+
+Do you enjoy outdoor activities?
+What types of outdoor activities do you do?
+How much time do you spend outdoors each week?
+What are some popular outdoor activities in your country?
+
+How long do you sleep for each day?
+Do you get enough sleep each night?
+How many hours of sleep does a person need to be healthy?
+How can someone improve their sleeping pattern?
+Do people need more sleep as they get older?
+
+How would you describe your ideal job?
+Why would you like this ideal job?
+Are you taking any steps to reach this goal?
+Is it important for each person to find his ideal job?
blob - /dev/null
blob + 25e50d35fd1ee101a16ad4af7e51107e8b551c38 (mode 644)
--- /dev/null
+++ loremipsum4
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + 7c1212dfa5c131cdf18315ccd7dc8186f60dbfee (mode 644)
--- /dev/null
+++ loremipsum5
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + 4d39a30b9d7aff13a5151ae46ef914436117d718 (mode 644)
--- /dev/null
+++ loremipsum6
+Part 1:
+ Where do you usually get your news?
+ Do you follow the news regularly?
+ What type of news do you like to read?
+ How do your peers normally get the news?
+ Do you think journalism is important?
+
+ How often do you use computers?
+ What types of computers do you use most often?
+What do you use computers for?
+ Do you think children should be taught how to use computers in school?
+How have computers changed the world?
+
+What types of hobbies do you enjoy?
+How did you first get started with your hobby?
+ How much time do you spend on your hobby?
+What do you enjoy about this hobby?
+Would you recommend this hobby to others?
+
+Do you often watch television ?
+What types of programs do you watch?
blob - /dev/null
blob + ee522b6e071437d7fd85f3cc04d39c394cbfe9b1 (mode 644)
--- /dev/null
+++ twos.c
+#include <stdio.h>
+
+int main() {
+ int myInt;
+ myInt = 0xFFFFFFE2;
+ printf("%d\n",myInt);
+
+ return 0;
+}