Assignment #2 COP-4338, Programming III
Assignment 2 consists of two parts. Part one will create the data, which will be use in part 2.
Part1:
Write an application that creates 1000 random-sized-files on disk of 500KB maximum size. For this you can create a string buffer of random size, of up to 100 chars, and write it to the file. You can repeat this process create a new string and write it again to the same file. As each string is of random length the size of the files will also be random. Notice that each file will have 500KB only if all strings were of maximum size, but it is more likely to be smaller than 500KB.
Tips: Name your files with a sequence, such as [login to view URL], [login to view URL] … [login to view URL], so they can be easily read in a loop. Use time() as a seed for rand(), see sample code on moodle. Once you have the list of 1000 files you can proceed to part 2
Part 2:
Read the files created in part 1 and create a structure, which stores the text from the file and the file size. Create an array of these structures (one structure per file read). This will require calling malloc() and allocating contiguous space to store all the structures.
typedef struct file_txt
{
char filename[10];
char buffer[500*8*1000]; /* Null terminated txt from the file */
int size; /* size of the file */
} file_txt;
Tips: Notice that the variable buffer is not a pointer but allocates space to store the whole length of the string. This means that upon calling malloc to allocate the memory, it might fail. If this is the case you can halve the size in part1 until it works on your machine
Then, sort the array of structures by the size of the file. This will require moving them around in the array. Measure the time this sorting process takes. Output the sorted order of the files (file names) to a file ([login to view URL]) . You can implement any sorting algorithm you want as long as you use the same on the following section.
Free the memory, recreate the array of structures, and repeat the experiment, but this time instead of sorting the array of structures, create an array of pointers to each structure and sort the pointers based on the size of the structures they point to. As this time we are only moving pointers (ints), the sorting should be more efficient. Measure the time this takes and compare it to the previous. Append the sorted order of the file (file names) to the [login to view URL] file used before.
Create a Makefile which compiles all the involved files. Create a “.h”, “.c”, and tester.c file with your project , as on assignment 1.
Note:
This code might be helpful in understating how to measure how long sorting takes:
#include <sys/time.h>
#include <time.h>
struct timeval start, stop;
gettimeofday(&start,NULL);
sort_here();
gettimeofday(&stop,NULL);
elapsed = 1000000 * (stop.tv_sec - start.tv_sec);
elapsed += stop.tv_usec - start.tv_usec;
// time in usecs
printf ("%lu;\t", elapsed);
Dear sir,
I've read your spec carefully. It's simple work.
With 10 years experience in C++, I could be a good fit.
I can complete it within 24-36 hours.
Kind regards,
Tin Tan
$60 USD en 1 día
4,6 (7 comentarios)
3,2
3,2
17 freelancers están ofertando un promedio de $117 USD por este trabajo
Hello
I'm interesting your project very well
I'm a Good C/C++, Linux, Algorithm expert.
I understand your req exactly.
I m quite well experienced in these assignment jobs.
Let's go ahead with me
I want to service for you continously.
Thanks
Hello
I am C expert with a lot of experience in helping students with assignments and tutoring.
I have reviewed your requirements and understood it. I am familiar with file read and time in C and confident to handle this project perfectly.
Please communicate to discuss further.
Regards
Anshu
Hi,
We have checked your requirement and understand that you need same file create using looping each file char length equal .
We are very happy to work with you. We are new to the elance but have more experience in the Software development and web development area.
thanks
Hy.
I'm quite proficient in C and everything Unix. I'm a CS student in Vienna, and also a full time Senior Operator of our Governments e-health system.
Algorithms and Datastructures come easy to me.
I can deliver in 1 day (or less) on your task.
Kind regards,
odb9088