I having problems trying to write a certain program and if anyone out
there could help me, I'd be very appreciative. To do this program,
you will need to download prog06_stuff.h from the following web site
and #include it in the prog06.h header file - the functions you
create will be in a header file named prog06.h and you can test these
functions with a C program of your making. The functions in
prog06_stuff.h require the randint.h header file be present in the
same folder. You can download it here:
http://www.egr115.com/randint.h.
You must #include prog06_stuff.h in the prog06.h file - From within
the test program, call the makefile() function in prog06_stuff.h file
to generate a data file for testing. The file structure will be one
string per line, and the last line will NOT have a newline after it.
void makefile(char *filename); The function makefile() is inside
prog06_stuff.h - it takes the name for a file to be created and
creates a text file for you, formally returning nothing. However,
after calling the function, a file with the name you sent into the
function will exist in the current directory, and that file will be
formatted with random strings which you can then read and sort. You
are guaranteed that all strings will start with an uppercase letter.
Write a function readfile() inside prog06.h such that follows this
prototype:
str_array *readfile(char *filename);
The function will read in a series of strings from the data file with
the name filename and return a pointer to a str_array struct. A
str_array is a struct that follows this definition (specified in
prog06_stuff.h):
typedef struct {
char strings[50][100];
} str_array;
Because the struct is not being sent into the function (you are only
sending in the name of the file), you will have to instantiate the
struct from inside the readfile() function. Recall that memory
statically allocated inside a function disappears when the function
ends. Therefore, in order for this struct to
remain in memory after the function exits, you *must* dynamically
allocate the memory for that struct - use calloc() to do so. The
memory will be freed at the end of main().
Write the function SortStruct() inside prog06.h that will take as
input two str_array pointers and, using the BubbleSort algorithm,
sort the strings in the struct in ascending order â" the original
struct is pointed to by in; the sorted struct is pointed to by out:
void SortStruct(str_array *in, str_array *out);
The argument (in the function call) for the in pointer will be the
same variable used to hold the result that came from readfile(). For
the out pointer, statically allocate the memory in main() and send
the address of that struct into SortStruct() as the function call
argument for out. Inside the function, copy the contents of the in
struct into the out struct, then sort the contents of the out struct
using the BubbleSort algorithm. As a separate header file named
p6xc.h, provide a function that follows this prototype
void xcSortStrings(char strings[50][100]) ;
and that will sort the strings using the qsort() function. In the
p6xc.h file, you will need to create a separate function to provide
to qsort() as a function pointer, and you will also need to provide
the readfile() function you created in the original assignment.
#include prog06_stuff.h so that you have the struct definition
available.