Question
A c programming student asked The program will require the following structure: struct _data { char *first, *middle, *last long number; }; The program will
A c programming student asked
The program will require the following structure:
struct _data {
char *first, *middle, *last
long number;
};
The program will require command line arguments:
int main(int argv, char **argc) {
Where argv is the number of arguments and argc is an array
holding the arguments (each is a string). Your program must catch
any case where no command line arguement was provided and print
a warning message (see below).
You MUST include/use the following functions, defined as follows:
int SCAN(FILE *(*stream)) - this function will open the file/stream
and return an integer indicating how many lines there are. Note that
I need to pass stream, which is a pointer, by reference. So I am
passing this as a pointer to a pointer.
struct _data *LOAD(FILE *stream, int size) - this function will
rewind file, create the dynamic array (of size), and read in the
data, populating the _data struct dynamic array. Note that stream
is passed by value this time. The function then returns the populated
array of struct.
void SEARCH(struct _data *BlackBox, char *name, int size) - this function
will get the dynamic array of struct passed to it, the name we are looking
for, and the size of the array. This function will then search the dynamic
array for the name. See below for examples.
void FREE(struct _data *BlackBox, int size) - this function will free up
all of the dynamic memory we allocated. Take note of the number of times
malloc/calloc were called, as you need to free that same number.
Finally, the data file will be called hw6.data and will be formated as:
ron jonny johnson 7774013
jon ronny johnsen 7774014
tom jones smith 7774015
won ton lee 7774016
You code MUST be able to handle cases where the names are VERY long.
HINTS:
------
Functions that will make things much easier:
getline()
feof()
strtok()
atoi()
* Make sure you read the man pages for each. They have some "gotchas".
SAMPLE RUNS:
------------
Case 1 - No command line argument provided.
[cat@chef junk]$ ./CS230-5
*******************************************
* You must include a name to search for. *
*******************************************
Case 2 - Provided name is NOT in the list.
[cat@chef junk]$ ./CS230-5 joe
*******************************************
The name was NOT found.
*******************************************
Case 3 - Search by FIRST name (name is in the list).
[cat@chef junk]$ ./CS230-5 tom
*******************************************
The name was found at the 2 entry.
*******************************************
Case 4 - Search by FIRST and LAST name (name is in the list, note the "_"
wildcard).
[cat@chef junk]$ ./CS230-5 tom _ smith
*******************************************
The name was found at the 2 entry.
*******************************************
Case 4 - Search by FIRST, MIDDLE, and LAST name (name is in the list).
[cat@chef junk]$ ./CS230-5 tom jones smith
*******************************************
The name was found at the 2 entry.
*******************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started