📄 programs.shar
字号:
#! /bin/sh# This is a shell archive. Remove anything before this line, then unpack# it by saving it into a file and typing "sh file". To overwrite existing# files, type "sh file -c". You can also feed this as standard input via# unshar, or by typing "sh <file", e.g.. If this archive is complete, you# will see the following message at the end:# "End of shell archive."# Contents: programs programs/02-Learning-by-Example# programs/03-Problem-Solving programs/04-Statement-Forms# programs/05-Functions programs/06-Algorithms programs/07-Graphics# programs/08-Random-Numbers programs/09-Strings# programs/10-Modular-Development programs/11-Arrays# programs/12-Sorting programs/13-Pointers# programs/14-Strings-Revisited programs/15-Text-Files# programs/16-Records programs/17-Looking-Ahead# programs/02-Learning-by-Example/Makefile# programs/02-Learning-by-Example/add2.c# programs/02-Learning-by-Example/add2f.c# programs/02-Learning-by-Example/ave2f.c# programs/02-Learning-by-Example/cmtofeet.c# programs/02-Learning-by-Example/greeting.c# programs/02-Learning-by-Example/hello.c# programs/02-Learning-by-Example/inchtocm.c# programs/03-Problem-Solving/Makefile# programs/03-Problem-Solving/add10.c# programs/03-Problem-Solving/addlist.c# programs/03-Problem-Solving/balance1.c# programs/03-Problem-Solving/balance2.c# programs/03-Problem-Solving/balance3.c# programs/03-Problem-Solving/balance4.c# programs/03-Problem-Solving/count10.c# programs/03-Problem-Solving/roses.c# programs/04-Statement-Forms/Makefile# programs/04-Statement-Forms/addlist.c# programs/04-Statement-Forms/cardrank.c# programs/04-Statement-Forms/digitsum.c# programs/04-Statement-Forms/leapyear.c# programs/04-Statement-Forms/liftoff.c# programs/04-Statement-Forms/oddeven.c# programs/04-Statement-Forms/signtest.c# programs/04-Statement-Forms/timestab.c# programs/05-Functions/Makefile programs/05-Functions/c2ftable.c# programs/05-Functions/calendar.c programs/05-Functions/combine.c# programs/05-Functions/fact.c programs/05-Functions/gameloop.c# programs/05-Functions/iseven.c programs/06-Algorithms/Makefile# programs/06-Algorithms/euclid.c programs/06-Algorithms/gcd.c# programs/06-Algorithms/nsqrt.c programs/06-Algorithms/primes1.c# programs/06-Algorithms/primes2.c programs/06-Algorithms/primes3.c# programs/06-Algorithms/tsqrt.c programs/06-Algorithms/zeno.c# programs/07-Graphics/Makefile programs/07-Graphics/arc1.c# programs/07-Graphics/arc2.c programs/07-Graphics/drawbox.c# programs/07-Graphics/drawcbox.c programs/07-Graphics/drawcirc.c# programs/07-Graphics/house.c programs/07-Graphics/oneline.c# programs/08-Random-Numbers/Makefile# programs/08-Random-Numbers/cointest.c# programs/08-Random-Numbers/craps.c# programs/08-Random-Numbers/dicetest.c# programs/08-Random-Numbers/random.c# programs/08-Random-Numbers/random.h# programs/08-Random-Numbers/randtest.c programs/09-Strings/Makefile# programs/09-Strings/acronym.c programs/09-Strings/addlist.c# programs/09-Strings/lastchar.c programs/09-Strings/linelen.c# programs/09-Strings/ncopies.c programs/09-Strings/protect.c# programs/09-Strings/repfirst.c programs/09-Strings/reverse.c# programs/09-Strings/secondh.c# programs/10-Modular-Development/Makefile# programs/10-Modular-Development/piglatin.c# programs/10-Modular-Development/scanner.c# programs/10-Modular-Development/scanner.h# programs/11-Arrays/Makefile programs/11-Arrays/countlet.c# programs/11-Arrays/gymjudge.c programs/11-Arrays/reverse.c# programs/11-Arrays/testrev.c programs/12-Sorting/Makefile# programs/12-Sorting/findcoin.c programs/12-Sorting/mileage.c# programs/12-Sorting/mileage2.c programs/12-Sorting/sort.c# programs/12-Sorting/sort.h programs/12-Sorting/testsort.c# programs/13-Pointers/Makefile programs/13-Pointers/hours.c# programs/13-Pointers/sort.c programs/13-Pointers/sort.h# programs/13-Pointers/testsort.c# programs/14-Strings-Revisited/Makefile# programs/14-Strings-Revisited/invert.c# programs/15-Text-Files/Makefile programs/15-Text-Files/copyfile.c# programs/15-Text-Files/elements.c# programs/15-Text-Files/elements.dat# programs/15-Text-Files/hamlet.txt# programs/15-Text-Files/juliet.txt# programs/15-Text-Files/linecopy.c programs/15-Text-Files/remcom.c# programs/15-Text-Files/showfile.c programs/15-Text-Files/ucfile.c# programs/15-Text-Files/witches.txt programs/16-Records/Makefile# programs/16-Records/advent.dat programs/16-Records/cs.dat# programs/16-Records/empdb.c programs/16-Records/employee.c# programs/16-Records/point.c programs/16-Records/teach.c# programs/17-Looking-Ahead/Makefile# programs/17-Looking-Ahead/fact.c# programs/17-Looking-Ahead/permute.c# programs/17-Looking-Ahead/power.c# programs/17-Looking-Ahead/qtest.c# programs/17-Looking-Ahead/queue.c# programs/17-Looking-Ahead/queue.h programs/17-Looking-Ahead/sort.c# programs/17-Looking-Ahead/sort.h# programs/17-Looking-Ahead/testsort.c# Wrapped by eroberts@Eeyore.Stanford.EDU on Fri Oct 21 13:36:56 1994PATH=/bin:/usr/bin:/usr/ucb ; export PATHif test ! -d 'programs' ; then echo shar: Creating directory \"'programs'\" mkdir 'programs'fiif test ! -d 'programs/02-Learning-by-Example' ; then echo shar: Creating directory \"'programs/02-Learning-by-Example'\" mkdir 'programs/02-Learning-by-Example'fiif test ! -d 'programs/03-Problem-Solving' ; then echo shar: Creating directory \"'programs/03-Problem-Solving'\" mkdir 'programs/03-Problem-Solving'fiif test ! -d 'programs/04-Statement-Forms' ; then echo shar: Creating directory \"'programs/04-Statement-Forms'\" mkdir 'programs/04-Statement-Forms'fiif test ! -d 'programs/05-Functions' ; then echo shar: Creating directory \"'programs/05-Functions'\" mkdir 'programs/05-Functions'fiif test ! -d 'programs/06-Algorithms' ; then echo shar: Creating directory \"'programs/06-Algorithms'\" mkdir 'programs/06-Algorithms'fiif test ! -d 'programs/07-Graphics' ; then echo shar: Creating directory \"'programs/07-Graphics'\" mkdir 'programs/07-Graphics'fiif test ! -d 'programs/08-Random-Numbers' ; then echo shar: Creating directory \"'programs/08-Random-Numbers'\" mkdir 'programs/08-Random-Numbers'fiif test ! -d 'programs/09-Strings' ; then echo shar: Creating directory \"'programs/09-Strings'\" mkdir 'programs/09-Strings'fiif test ! -d 'programs/10-Modular-Development' ; then echo shar: Creating directory \"'programs/10-Modular-Development'\" mkdir 'programs/10-Modular-Development'fiif test ! -d 'programs/11-Arrays' ; then echo shar: Creating directory \"'programs/11-Arrays'\" mkdir 'programs/11-Arrays'fiif test ! -d 'programs/12-Sorting' ; then echo shar: Creating directory \"'programs/12-Sorting'\" mkdir 'programs/12-Sorting'fiif test ! -d 'programs/13-Pointers' ; then echo shar: Creating directory \"'programs/13-Pointers'\" mkdir 'programs/13-Pointers'fiif test ! -d 'programs/14-Strings-Revisited' ; then echo shar: Creating directory \"'programs/14-Strings-Revisited'\" mkdir 'programs/14-Strings-Revisited'fiif test ! -d 'programs/15-Text-Files' ; then echo shar: Creating directory \"'programs/15-Text-Files'\" mkdir 'programs/15-Text-Files'fiif test ! -d 'programs/16-Records' ; then echo shar: Creating directory \"'programs/16-Records'\" mkdir 'programs/16-Records'fiif test ! -d 'programs/17-Looking-Ahead' ; then echo shar: Creating directory \"'programs/17-Looking-Ahead'\" mkdir 'programs/17-Looking-Ahead'fiif test -f 'programs/02-Learning-by-Example/Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/Makefile'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/Makefile'\" \(1698 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/Makefile' <<'END_OF_FILE'X# Makefile for cbook/02-Learning-by-Example/programsX# Created by the ExportAll facilityX# ***************************************************************XXPROGRAMS = \X hello \X add2 \X add2f \X greeting \X inchtocm \X ave2f \X cmtofeet XX# ***************************************************************X# Parameters to control Makefile operationX# Note that the gccx command script must be definedXXCC = gccxXCFLAGS = XX# ***************************************************************X# Entry to bring the package up to dateXXall: $(PROGRAMS)XX# ***************************************************************X# Standard entries to remove files from the directoriesX# tidy -- eliminate unwanted filesX# scratch -- delete derived files in preparation for rebuildXXtidy:X rm -f ,* .,* *~ core a.out graphics.psXXscratch: tidyX rm -f *.o *.a $(PROGRAMS)XX# ***************************************************************X# C compilationsXXhello.o: hello.cX $(CC) $(CFLAGS) -c hello.cXXadd2.o: add2.cX $(CC) $(CFLAGS) -c add2.cXXadd2f.o: add2f.cX $(CC) $(CFLAGS) -c add2f.cXXgreeting.o: greeting.cX $(CC) $(CFLAGS) -c greeting.cXXinchtocm.o: inchtocm.cX $(CC) $(CFLAGS) -c inchtocm.cXXave2f.o: ave2f.cX $(CC) $(CFLAGS) -c ave2f.cXXcmtofeet.o: cmtofeet.cX $(CC) $(CFLAGS) -c cmtofeet.cXXXhello: hello.oX $(CC) $(CFLAGS) -o hello hello.oXXadd2: add2.oX $(CC) $(CFLAGS) -o add2 add2.oXXadd2f: add2f.oX $(CC) $(CFLAGS) -o add2f add2f.oXXgreeting: greeting.oX $(CC) $(CFLAGS) -o greeting greeting.oXXinchtocm: inchtocm.oX $(CC) $(CFLAGS) -o inchtocm inchtocm.oXXave2f: ave2f.oX $(CC) $(CFLAGS) -o ave2f ave2f.oXXcmtofeet: cmtofeet.oX $(CC) $(CFLAGS) -o cmtofeet cmtofeet.oEND_OF_FILEif test 1698 -ne `wc -c <'programs/02-Learning-by-Example/Makefile'`; then echo shar: \"'programs/02-Learning-by-Example/Makefile'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/Makefile'fiif test -f 'programs/02-Learning-by-Example/add2.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/add2.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/add2.c'\" \(430 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/add2.c' <<'END_OF_FILE'X/*X * File: add2.cX * ------------X * This program reads in two numbers, adds them together,X * and prints their sum.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X int n1, n2, total;XX printf("This program adds two numbers.\n");X printf("1st number? ");X n1 = GetInteger();X printf("2nd number? ");X n2 = GetInteger();X total = n1 + n2;X printf("The total is %d.\n", total);X}END_OF_FILEif test 430 -ne `wc -c <'programs/02-Learning-by-Example/add2.c'`; then echo shar: \"'programs/02-Learning-by-Example/add2.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/add2.c'fiif test -f 'programs/02-Learning-by-Example/add2f.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/add2f.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/add2f.c'\" \(458 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/add2f.c' <<'END_OF_FILE'X/*X * File: add2f.cX * -------------X * This program reads in two floating-point numbers, adds themX * together, and prints their sum.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double n1, n2, total;XX printf("This program adds two floating-point numbers.\n");X printf("1st number? ");X n1 = GetReal();X printf("2nd number? ");X n2 = GetReal();X total = n1 + n2;X printf("The total is %g\n", total);X}END_OF_FILEif test 458 -ne `wc -c <'programs/02-Learning-by-Example/add2f.c'`; then echo shar: \"'programs/02-Learning-by-Example/add2f.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/add2f.c'fiif test -f 'programs/02-Learning-by-Example/ave2f.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/ave2f.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/ave2f.c'\" \(461 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/ave2f.c' <<'END_OF_FILE'X/*X * File: ave2f.cX * -------------X * This program reads in two floating-point numbers andX * computes their average.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double n1, n2, average;XX printf("This program averages two floating-point numbers.\n");X printf("1st number? ");X n1 = GetReal();X printf("2nd number? ");X n2 = GetReal();X average = (n1 + n2) / 2;X printf("The average is %g\n", average);X}END_OF_FILEif test 461 -ne `wc -c <'programs/02-Learning-by-Example/ave2f.c'`; then echo shar: \"'programs/02-Learning-by-Example/ave2f.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/ave2f.c'fiif test -f 'programs/02-Learning-by-Example/cmtofeet.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/cmtofeet.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/cmtofeet.c'\" \(565 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/cmtofeet.c' <<'END_OF_FILE'X/*X * File: cmtofeet.cX * ----------------X * This program reads in a length given in centimeters and convertsX * it to its English equivalent in feet and inches.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double totalInches, cm, inch;X int feet;XX printf("This program converts centimeters to feet and inches.\n");X printf("Length in centimeters? ");X cm = GetReal();X totalInches = cm / 2.54;X feet = totalInches / 12;X inch = totalInches - feet * 12;X printf("%g cm = %d ft %g in\n", cm, feet, inch);X}END_OF_FILEif test 565 -ne `wc -c <'programs/02-Learning-by-Example/cmtofeet.c'`; then echo shar: \"'programs/02-Learning-by-Example/cmtofeet.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/cmtofeet.c'fiif test -f 'programs/02-Learning-by-Example/greeting.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/greeting.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/greeting.c'\" \(364 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/greeting.c' <<'END_OF_FILE'X/*X * File: greeting.cX * ----------------X * This program prints a more personal greeting than didX * the original "Hello, world." program by reading in theX * name of the user.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X string user;XX printf("What is your name? ");X user = GetLine();X printf("Hello, %s.\n", user);X}END_OF_FILEif test 364 -ne `wc -c <'programs/02-Learning-by-Example/greeting.c'`; then echo shar: \"'programs/02-Learning-by-Example/greeting.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/greeting.c'fiif test -f 'programs/02-Learning-by-Example/hello.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/hello.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/hello.c'\" \(323 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/hello.c' <<'END_OF_FILE'X/*X * File: hello.cX * -------------X * This program prints the message "Hello, world."X * on the screen. The program is taken from theX * classic C reference text "The C ProgrammingX * Language" by Brian Kernighan and Dennis Ritchie.X */XX#include <stdio.h>X#include "genlib.h"XXmain()X{X printf("Hello, world.\n");X}END_OF_FILEif test 323 -ne `wc -c <'programs/02-Learning-by-Example/hello.c'`; then echo shar: \"'programs/02-Learning-by-Example/hello.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/hello.c'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -