From 5a86af46b08cc1eb22537ae8696de0b66dc68867 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 9 Sep 2011 09:17:53 -0400 Subject: [PATCH] breaking ex10 --- .gitignore | 1 + Makefile | 2 +- break-ex10.py | 10 ++++++++++ ex10.c | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 break-ex10.py create mode 100644 ex10.c diff --git a/.gitignore b/.gitignore index f65443b..54570d1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ ex6 ex7 ex8 ex9 +ex10 diff --git a/Makefile b/Makefile index 6edda90..4c0c244 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -g -EXERCISES = ex1 ex3 ex4 ex5 ex6 ex7 ex8 ex9 +EXERCISES = ex1 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 all: $(EXERCISES) diff --git a/break-ex10.py b/break-ex10.py new file mode 100644 index 0000000..bdba748 --- /dev/null +++ b/break-ex10.py @@ -0,0 +1,10 @@ +from __future__ import print_function + +import os +import sys + +argc = int(sys.argv[1]) if sys.argv[1:] else 23694 +command = "valgrind ./ex10 " + " ".join(map(str, range(argc))) +print("command = {}".format(command)) + +os.system(command) diff --git a/ex10.c b/ex10.c new file mode 100644 index 0000000..c06d77b --- /dev/null +++ b/ex10.c @@ -0,0 +1,22 @@ +#include + +int main(int argc, char *argv[]) +{ + int i = 0; + + for(i = 0; i < argc; i++) { + printf("arg %d: %s\n", i, argv[i]); + } + + char *states[] = { + "California", "Oregon", + "Washington", "Texas" + }; + int num_states = 4; + + for(i = 0; i < num_states; i++) { + printf("state %d: %s\n", i, states[i]); + } + + return 0; +}