#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 3_9a.c 3_9a.cmp 3_9atst.c 3_9b.c 3_9b.cmp 3_9btst.c makefile # # To extract the files from this shell archive file simply # create a directory for this file, move the archive file # to it and enter the command # # sh filename # # The files will be extracted automatically. # Note: Do not use csh. # # Archive created: Mon Jul 30 22:59:42 EDT 1990 # echo x - 3_9a.c sed 's/^X//' > 3_9a.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // concatenate the two strings s1 and s2 into // a new string allocated on the free store #include char *cat(const char *s1, const char *s2) { if (!s1 || !s2) return 0; int length1 = strlen(s1); char *ret = new char [ length1 + strlen(s2) + 1 ]; strcpy(ret, s1); strcpy(ret + length1, s2); return ret; } !EOF! ls -l 3_9a.c echo x - 3_9a.cmp sed 's/^X//' > 3_9a.cmp << '!EOF!' a='', b='', ab='' a='', b='The quick brown fox jumped over the lazy brown dog', ab='The quick brown fox jumped over the lazy brown dog' a='', b='This is a test', ab='This is a test' a='', b='abc', ab='abc' a='', b='abcd', ab='abcd' a='', b='abcda', ab='abcda' a='', b='abdc', ab='abdc' a='', b='hello there', ab='hello there' a='The quick brown fox jumped over the lazy brown dog', b='', ab='The quick brown fox jumped over the lazy brown dog' a='The quick brown fox jumped over the lazy brown dog', b='The quick brown fox jumped over the lazy brown dog', ab='The quick brown fox jumped over the lazy brown dogThe quick brown fox jumped over the lazy brown dog' a='The quick brown fox jumped over the lazy brown dog', b='This is a test', ab='The quick brown fox jumped over the lazy brown dogThis is a test' a='The quick brown fox jumped over the lazy brown dog', b='abc', ab='The quick brown fox jumped over the lazy brown dogabc' a='The quick brown fox jumped over the lazy brown dog', b='abcd', ab='The quick brown fox jumped over the lazy brown dogabcd' a='The quick brown fox jumped over the lazy brown dog', b='abcda', ab='The quick brown fox jumped over the lazy brown dogabcda' a='The quick brown fox jumped over the lazy brown dog', b='abdc', ab='The quick brown fox jumped over the lazy brown dogabdc' a='The quick brown fox jumped over the lazy brown dog', b='hello there', ab='The quick brown fox jumped over the lazy brown doghello there' a='This is a test', b='', ab='This is a test' a='This is a test', b='The quick brown fox jumped over the lazy brown dog', ab='This is a testThe quick brown fox jumped over the lazy brown dog' a='This is a test', b='This is a test', ab='This is a testThis is a test' a='This is a test', b='abc', ab='This is a testabc' a='This is a test', b='abcd', ab='This is a testabcd' a='This is a test', b='abcda', ab='This is a testabcda' a='This is a test', b='abdc', ab='This is a testabdc' a='This is a test', b='hello there', ab='This is a testhello there' a='abc', b='', ab='abc' a='abc', b='The quick brown fox jumped over the lazy brown dog', ab='abcThe quick brown fox jumped over the lazy brown dog' a='abc', b='This is a test', ab='abcThis is a test' a='abc', b='abc', ab='abcabc' a='abc', b='abcd', ab='abcabcd' a='abc', b='abcda', ab='abcabcda' a='abc', b='abdc', ab='abcabdc' a='abc', b='hello there', ab='abchello there' a='abcd', b='', ab='abcd' a='abcd', b='The quick brown fox jumped over the lazy brown dog', ab='abcdThe quick brown fox jumped over the lazy brown dog' a='abcd', b='This is a test', ab='abcdThis is a test' a='abcd', b='abc', ab='abcdabc' a='abcd', b='abcd', ab='abcdabcd' a='abcd', b='abcda', ab='abcdabcda' a='abcd', b='abdc', ab='abcdabdc' a='abcd', b='hello there', ab='abcdhello there' a='abcda', b='', ab='abcda' a='abcda', b='The quick brown fox jumped over the lazy brown dog', ab='abcdaThe quick brown fox jumped over the lazy brown dog' a='abcda', b='This is a test', ab='abcdaThis is a test' a='abcda', b='abc', ab='abcdaabc' a='abcda', b='abcd', ab='abcdaabcd' a='abcda', b='abcda', ab='abcdaabcda' a='abcda', b='abdc', ab='abcdaabdc' a='abcda', b='hello there', ab='abcdahello there' a='abdc', b='', ab='abdc' a='abdc', b='The quick brown fox jumped over the lazy brown dog', ab='abdcThe quick brown fox jumped over the lazy brown dog' a='abdc', b='This is a test', ab='abdcThis is a test' a='abdc', b='abc', ab='abdcabc' a='abdc', b='abcd', ab='abdcabcd' a='abdc', b='abcda', ab='abdcabcda' a='abdc', b='abdc', ab='abdcabdc' a='abdc', b='hello there', ab='abdchello there' a='hello there', b='', ab='hello there' a='hello there', b='The quick brown fox jumped over the lazy brown dog', ab='hello thereThe quick brown fox jumped over the lazy brown dog' a='hello there', b='This is a test', ab='hello thereThis is a test' a='hello there', b='abc', ab='hello thereabc' a='hello there', b='abcd', ab='hello thereabcd' a='hello there', b='abcda', ab='hello thereabcda' a='hello there', b='abdc', ab='hello thereabdc' a='hello there', b='hello there', ab='hello therehello there' !EOF! ls -l 3_9a.cmp echo x - 3_9atst.c sed 's/^X//' > 3_9atst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #include #include "3_9a.c" char *x[] = { "", "The quick brown fox jumped over the lazy brown dog", "This is a test", "abc", "abcd", "abcda", "abdc", "hello there", 0 }; main() { for (char **xp = x; *xp; xp++) for (char **yp = x; *yp; yp++) cout << "a='" << *xp << "', b='" << *yp << "', ab='" << cat(*xp, *yp) << "'\n"; return 0; } !EOF! ls -l 3_9atst.c echo x - 3_9b.c sed 's/^X//' > 3_9b.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // reverse the characters within the string s #include #include void rev(char *s) { if (!s) return; char *e = s + strlen(s) - 1; for ( ; s < e ; s++, e--) swap(*s, *e); } !EOF! ls -l 3_9b.c echo x - 3_9b.cmp sed 's/^X//' > 3_9b.cmp << '!EOF!' a='' rev='' a='The quick brown fox jumped over the lazy brown dog' rev='god nworb yzal eht revo depmuj xof nworb kciuq ehT' a='This is a test' rev='tset a si sihT' a='abc' rev='cba' a='abcd' rev='dcba' a='abcda' rev='adcba' a='abdc' rev='cdba' a='hello there' rev='ereht olleh' !EOF! ls -l 3_9b.cmp echo x - 3_9btst.c sed 's/^X//' > 3_9btst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #include #include "3_9b.c" char *x[] = { "", "The quick brown fox jumped over the lazy brown dog", "This is a test", "abc", "abcd", "abcda", "abdc", "hello there", 0 }; main() { for (char **xp = x; *xp; xp++) { cout << "a='" << *xp << "'\n"; rev(*xp); cout << "rev='" << *xp << "'\n"; } return 0; } !EOF! ls -l 3_9btst.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC all: 3_9atst 3_9btst 3_9atst: 3_9atst.c 3_9a.c $(CC) 3_9atst.c -o 3_9atst 3_9btst: 3_9btst.c 3_9b.c $(CC) 3_9btst.c -o 3_9btst test: all 3_9a.cmp 3_9b.cmp 3_9atst > 3_9a.out cmp 3_9a.out 3_9a.cmp 3_9btst > 3_9b.out cmp 3_9b.out 3_9b.cmp echo tests done !EOF! ls -l makefile # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0