Assignment 1, Solutions
Part of
the homework for 22C:169, Spring 2011
|
On my old (Power PC based) apple Mac:
[pyrite:~] jones% echo $HOSTTYPE $MACHTYPE powermac powerpc [pyrite:~] jones% cc --version powerpc-apple-darwin8-gcc-4.0.0 (GCC) 4.0.0 (Apple Computer, Inc. build 5026)On the departmental (Intel based) Linux cluster:
[jones@serv16 ~]$ echo $HOSTTYPE $MACHTYPE x86_64-linux x86_64 [jones@serv16 ~]$ cc --version cc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
No solution offered.
#include <stdio.h> /***************************************************************** * Hello World program * * Author: Kernighan and Ritchie * * Revised by: Douglas Jones * * Description: HW1 22C:169 - prints the address of string * *****************************************************************/ char hello[] = "Douglas W. Jones"; /* added in revision */ int main() { /* printf("Hello World!\n"); */ /* original */ /* printf("%s\n", hello); */ /* first revision */ printf("%lx\n", hello); */ /* first revision */ }
Working with the original Hello World program, modified to print my name, I used the vi editor to edit a.out, where I used the command
:/Douglas W. Jones/s//Arnold P. Hogget/
before saving the file. When I executed it, the output was changed to Arnold P. Hogget, as expected. Note that the changed name is the same exact length as the original.
#include <stdio.h> /***************************************************************** * Program to print out the address of one local variable * * Author: Douglas W. Jones * *****************************************************************/ void routine() { int i; printf("%lx\n", &i); } int main() { routine(); }