CSC415 Assignment -Command Line Arguments Solved

30.00 $

Category:

Description

5/5 - (1 vote)

 

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$
“`

You should submit your source code file(s), Makefile along with a short writeup in PDF format into your GIT repository and submit the PDF into the assignment in iLearn. Your write-up should include a description of the project and what you did, issues you had, how you overcame the issues and the compilation and execution output from your program (screen shots embedded in the PDF document. Your execution output should include commands with the command-line arguments.

All filenames should be `<lastname>_<firstname>_HW<#>_<component>.<proper extension>`
So my filename would be `Bierman_Robert_HW1_main.c`

“`
# File: Makefile

LASTNAME=Bierman
FIRSTNAME=Robert
HW=1

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)
“`

 

  • Command-Line-Arguments-project-main-gafnez.zip