Lab Setup
Note: This lab must be run on (CS105 not defined). If you run it on a different machine, you may get incorrect (or at least different) answers.
Source Code
You will be working with two simple programs (you don't need to, and shouldn't, edit these files):
#include <stdio.h>
#include <stdlib.h>
int loop_while(int a, int b)
{
int i = 0;
int result = a;
while (i < 256) {
result += a;
a -= b;
i += b;
}
return result;
}
int main(int argc, char *argv[])
{
printf("%d\n", loop_while(atoi(argv[1]), 16));
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int puzzle1 = 0x40490fdb;
int puzzle2[2] = {0x8b145769, 0x4005bf0a};
char puzzle3[] = {87, 97, 115, 32, 116, 104, 97, 116, 32, 114, 101,
97, 108, 108, 121, 32, 115, 111, 32, 104, 97, 114, 100, 63, 0};
int hmc_pomona_fix(int x)
{
if (x == 42)
return 47;
else if (x == 47)
return 42;
else
return x;
}
void fix_array(int *a, int a_size)
{
int i;
for (i = 0; i < a_size; i++, a++) {
*a = hmc_pomona_fix(*a);
}
}
int main(int argc, char *argv[])
{
int *array;
int i;
array = (int *)malloc(argc * sizeof(int));
/* argv[0] is the program name so we skip it */
for (i = 1; i < argc; i++) {
array[i] = atoi(argv[i]);
}
fix_array(array, argc - 1);
for (i = 1; i < argc; i++) {
printf ("%d ", array[i]);
}
printf ("\n");
return 0;
}
Answers File
In the following steps, you will be running commands and generating
answers to questions. You and you partner will put the answers into
a text file named lab02.txt, which will be submitted at the end of
the lab.
The first line of the file should have your and your partner's names.
For the rest of the file, identify each section by problem number, and each answer by question number.
(When logged in, completion status appears here.)