100 Intermediate C Programming
void my_stru pper ( char * str );20
// - --- --- --- --- --- --- --- - --- --- --- --- --- --- --- - --- --- -21
// Return the pointer to the first o ccurrence of the character22
// If the character is not in the string , return NULL .23
// Example : char * str = " foobar ";24
// my_s trchr ( foobar , ’b ’) is the address of str [3]25
char * m y_strchr ( const char * str , char ch) ;26
#e ndif /* M YSTRING_H */27
Notice that my strlen and my countchar have const for the arguments but
my strupper does not. By adding const in front of an argument, this header file says
the input argument is a constant and cannot be changed inside of the function. This is im-
portant when an argument is a pointer. A pointer’s value is a memory address. Through the
pointer, it is possible to change the value at that memory address. Adding const prevents
a function from making such a change. If the function unintentionally changes the value at
that memory address, gcc will detect that. This is a good strategy in writing programs:
asking gcc to detect unintended changes. The function my strupper has no const because
the input string will be changed: The lowercase letters are changed to the uppercase letters.
7.1.4 Creating Inputs and Correct Outputs
Before writing a program, we should first develop a strategy for testing. To do this we
need test inputs and the correct outputs for those inputs. For this program, we use the
beginning of Albert Einstein’s Nobel speech as the test input:
If we co nsider that part of the theory of re l ativi t y which may1
now adays in a sense be r egard ed as bona fide scient ific knowledge , we2
note two aspects which have a maj or bear ing on this theory . The whole3
deve lopment of the theory turns on the q uesti on of whet her there are4
phy s ically p refer red stat es of motion in N ature ( p hysic al rela tivity5
problem ) . Also , co ncept s and disti nctions are only admis sible to the6
extent that obser vable facts can be assig ned to them without7
amb iguit y ( stipu l ation that conc epts and disti n ctions should have8
meaning ) . This postulate , perta i ning to epistemology , proves to be of9
fund amental i mporta nce .10
11
These two aspects bec ome clear when applied to a special case , e . g.12
to classical mecha nics . Firstly we see that at any point filled with13
matter there exists a p referr ed state of motion , namely that of the14
sub stanc e at the point consid ered . Our pro blem starts howe ver with15
the que stion whether p hysica lly pre ferred states of motion exist in16
ref erenc e to ex tensi ve regions . From the viewpoint of cl assica l17
mec hanic s the answer is in the affir mative ; the physic ally p refer red18
states of motion from the view point of mecha nics are those of the19
ine rtial frames .20
21
This assertion , in co mmon with the basis of the whole of m echan ics as22
it generally used to be descr ibed before the relat ivity theory , far23
from meets the above " sti pulatio n of meani ng ". Motion can only be24
con ceive d as the relat ive motion of bodies . In mechanics , motion25
rel ative to the system of coor d inates is implied when merely mot ion26
is refe rred to . Neve r theless this i n terpreta t i on does not c omply with27
the " stip u lation of meaning " i f the coor dinate system is consi dered28
as something purely imagi nary . If we turn our atte ntion to29