#### connect to your csci235 directory cd ~/csci235 #### using your favorite text editor, create a C file containing the following code #### I'll call my file funlab.c #include #include int main(int argc, char *argv[]) { for (int i=0; i>>> MYFILE=`echo $1 | cut --fields=1 --delimiter=.` >>>> echo gcc -std=c99 -Wpedantic -o $MYFILE $1 >>>> gcc -std=c99 -Wpedantic -o $MYFILE $1 >>>> } #### Try it out! $$$$ c235 funlab.c $$$$ ls -lt funlab $$$$ funlab #### but.... How to you make this last! $$$$ echo $PATH #### You should see your bin directory! #### Create a file /home/YOURID/bin/c235 with the following contents #! /bin/bash PREFIX=`echo $1 | cut --fields=1 --delimiter=.` echo RUNNING: gcc -std=c99 -Wpedantic -o $PREFIX $1 gcc -std=c99 -Wpedantic -o $PREFIX $1 #### Make sure it is executable $$$$ chmod a+x ~/bin/c235 $$$$ ls -l ~/bin/c235 #### Be sure the shell can find it! And then try it out $$$$ c235 funlab.c $$$$ funlab #### Try to compile your program with the defaults! $$$$ gcc funlab.c #### Make the changes shown in the following diff and recompile 5c5 < for (int i=0; i for (int i=0; i<100; ++i) { #### Run it... This will not go well #### Type the command "env" to see where these values came from $$$$ env #### Modify your program to print the pointer not its value. Here's a diff 6c6 < printf("arg %3d is %s\n", i, argv[i]) ; --- > printf("arg %3d is %d\n", i, argv[i]) ; #### You get a "pedantic" error. Go ahead and run it! #### Let's get rid of the 100. Go back to argc. #### Take a *long* look at the man page for fprintf. The reference to a pointer! #### Change the format to print argv[i] as a pointer. (Use %p.) #### Ugh -- hex... Try %d. #### Ugh -- Try to cast argv[i] to (int) #### Ugh -- Try to cast argv[i] to (void *) -- that is the "generic" pointer #### Ugh -- Try to cast argv[i] to (void *) to (int), that is (int)(void *) #### Ugh -- Different sizes... Change the (int) to (long) #### Ugh -- Change format specifier to %ld #### Wait... I liked the HEX better than that. Go to %lx. #### But it's 64 bits... that's 4*16. Try %16lx . #### ALL CAPS would look better. Try %16lX #### Let's have some leading zero's. That's %016lX #### Let's add the string back in. The output should be something like: arg 0 is at 00007FFCD9248D59 and is ./funlab arg 1 is at 00007FFCD9248D62 and is do arg 2 is at 00007FFCD9248D65 and is me arg 3 is at 00007FFCD9248D68 and is ri