Question: PROBLEM: Write a C program to figure out how many integers fall between two given integers, and then write a makefile to pull the whole

PROBLEM:
Write a C program to figure out how many integers fall between two given integers, and then
write a makefile to pull the whole program all together.
The solution will be created in a typical source code directory structure, using subdirectories and
include files.
We will also create a Shell Script and practice using the Unix find command.
LAB SET-UP
Create a "lab5" directory under your /csc60 directory. (Note: means "your home directory",
same as your $HOME shell variable)
For this lab, we'll create a project structure under the lab5 directory which will be our project
source code directory structure:
First, create a directory named "myApp" under your /csc60 directory/lab5.
Then, create two additional directories named "utils" and "include" under your myApp
directory.
You should end up with the following directories:
/csc60/lab5/myApp/utils
/csc60/lab5/myApp/include
Within this structure you will be creating the following 7 files:
myApp/main.c
myApp/getRange.c
myApp/printFuns.C
myApp/makefile
myApp/include/lab5.h
myApp/include/utils.h
When complete, your source code directory with files should look like this:
Now, create the files for the project: Try to take it one step at a time, it's easier to start with a small amount of code, get that
building and then expand step by step. A makefile helps with this since you don't need to
keep track of what to rebuild and how to do it... just type "make" after making changes.
So, create the makefile early in the process so you can use it while you finish creating your
.c and .h files.
Create the project makefile:
Model your makefile on the example in the Week 5 Lecture slide deck, slide #14(feel free to
experiment with implicit rules, slide #15)
You'll need to adjust for the file names and directory structure of this source code project
Instead of "charProg", use the executable name "printRange"
Do this first because you'll want to run make to build the executable (the cc commands) as
you fill out the source code contents.
In your makefile:
include your name, class section # and current semester as lines in the comment block at
the top of the makefile.
Add a macro CC= gcc at the top of your makefile, then use $(CC) in the compile/link
commands (see slide 15 in the Week 5 lecture slides for an example)
Include the following rule in your makefile. Be very careful that the file names are correct!
clean:
$(RM) printRange *.0*.a
Create include/lab5.h
An "include file" which has one line in it:
#define TITLE "
Range Counter Report
"
Create include/utils.h
This is include used to provide "extern" references to the utility functions for main.c
It should be included wherever it's needed, i.e. any .c files that call functions in utils.
In utils.h, you need the function prototypes for the two utility functions so main.c will be able
to compile. The prototypes should look like:
Create getRange.c
Contains one function "getRange(int, int)"
Add the logic in getRange() as stated in the comment below:
int getRange( int firstNum, int lastNum){/* calc and return the number of integers between firstNum and lastNum
e.g. there are 4 integers between 1 and 6, namely: (2,3,4,5)*?
Create printFuns.c - Contains two functions:
"printHeader()" and "printDataLine(int, int, int)"
/* Function to print the header into the provided file */
void printHeader(){
printf(TITLE);
printf("The count of integers in a range:
");
printf(" lst Num 2nd Num # between
");
printf("------------------------
");
}
/* Function to print the header into the provided file */
void printDataLine(int fNum, int lNum, int range){
FILL IN THE LOGIC HERE, needs to "fit" with header line >
}
You will need to #include the lab5.h to have access the pre-processor macro TITLE
Create main.c file:
This is where you will have your main function.
Start with the basic structure of a file that defines variables, loops while gathering input data
from the user to processes and display the results of each entry.
Think about what #include lines are needed in main.c
The loop in main() will be terminated by entering the values 0 and 0
Build your project
Run make. Note, you will likely have to incrementally get it all working, i.e. run it, observe
errors, fix those then try again. That's normal, and make makes it easier )
Run getRange
Run the getRange executable with the following input: Note, each set of input should result in
a "report"
48
5{:[5,10]
1100
1020 The output should look something like:
$ ./printRange
Enter first number: 4
Enter last number: 8
Range Counter Report
The count of integers in a range:
1st Num 2nd Num # betweenREMINDERS:
(1) Remember to put your name as a comment at the top of each code file you submit.
(2) You should examine the data files and confirm the correctness of the answer produced by
your program.
PROBLEM: Write a C program to figure out how many

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!