$30
This program is to demonstrate the usage of command line arguments in a C program. You will write this to run in the Linux virtual machine. The program should display the number of arguments from the command line and list each one on the console.
Here is a sample execution:
student:~/CSC415$ make run RUNOPTIONS="Hello, these are overridden options 3 6 9"
gcc -c -o bierman_robert_hw1_main.o bierman_robert_hw1_main.c -g -I.
gcc -o bierman_robert_hw1_main bierman_robert_hw1_main.o -g -I.
./bierman_robert_hw1_main Hello, these are overridden options 3 6 9
There were 9 arguments on the command line.
Argument 00: ./bierman_robert_hw1_main
Argument 01: Hello,
Argument 02: these
Argument 03: are
Argument 04: overridden
Argument 05: options
Argument 06: 3
Argument 07: 6
Argument 08: 9
student:~/CSC415$
# File: Makefile
RUNOPTIONS=Hello World
ROOTNAME=$(LASTNAME)_$(FIRSTNAME)_HW
FOPTION=_main
CC=gcc
CFLAGS= -g -I.
# To add libraries, add "-l <libname>", for multiple repeat prior for each lib.
LIBS =
DEPS =
OBJ = $(ROOTNAME)$(HW)$(FOPTION).o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
$(ROOTNAME)$(HW)$(FOPTION): $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
clean:
rm *.o $(ROOTNAME)$(HW)$(FOPTION)
run: $(ROOTNAME)$(HW)$(FOPTION)
./$(ROOTNAME)$(HW)$(FOPTION) $(RUNOPTIONS)