Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

your job is to (1) find a user-specified text string within a group of disk files, (2) modify those strings and update the original disk

image text in transcribedyour job is to (1) find a user-specified text string within a group of disk files, (2) modify those strings and update the original disk files, and then (3) provide a report that indicates what has been done. It will work as follows:

1. The application will take a single command argument. This argument will be interpreted as a text string. For example, if your program was called replace.exe, you might enter replace.exe apple. Note that if you are using the Eclipse C/C++ plugin as your IDE, you can use a Run Configuration to specify the command line argument. 2. You will then open each of the files in the current directory. If you havent done much programming with files and directories, it isnt especially difficult. That said, the facilities for doing so in C are somewhat more primitive than those in languages such as Java. First, you will want to make use of the functions associated with . As we discussed in class, these are the basic IO functions, and can be applied not only to the screen and keyboard, but to disk files as well (There are countless online examples of basic C I/O). Here, you will use functions for opening and closing files, reading and writing bytes/chars to and from files, and for checking to see to see if you have reached the end of the file. 3. In addition to opening and reading files, you must also be able to read the contents of the directory in order to see what files need to be checked (the current directory = .). Basically, a directory is just a special type of file that contains a list of the files within it. So the idea is to just loop through the file list, and open and examine each text file (for simplicity, all files used during testing will be text files with a .txt suffix, so you dont have to worry about other formats). Unfortunately (for you), reading directories is operating system dependent since it is closely associated with the file system used by the host operating system. IMPORTANT: The grading will be done in the same environment as the one employed by the labs and the Facultys main login servers. This is Linux based. So the program must run on these platforms. You can NOT use directory functions that are Windows specific. So regardless of where you write your code, you must test your code on a Linux/Unix system (note that you can do this remotely via SSH - by simply compiling the code on the university servers that all students have access to). In terms of the actual mechanisms for traversing directories on Linux/Unix, it is again not very hard. Essentially, the standard technique is to open the directory and use a WHILE loop to examine the contents (i.e., the individual files). With Linux/Unix systems, the directory functions (e.g., opening and reading directories) are associated with the header file . You may also want to include and . 4. For each text file found in the directory, you will open each and check for the string that was entered at the command line. The target string may occur multiple times, of course. When you find it, you will modify the text so that the target string is printed in upper case. So, for example, if apple is the target, the string the Big Apple is fun would become the Big APPLE is fun. Please note that while this kind of update can be done with complex regular expression libraries, you will not do that here. Instead, you will just be flipping the lowercase letters to uppercase as required. String related functions are found in while character functions are in . 5. To make things just a little more interesting, directories can be nested. So if the current directory has sub directories, you must search those as well. Note that when you read the directory contents in the main WHILE loop, you can check each entry to determine if it is a regular file or another directory (there are constants defined in for this purpose.). Again, there are simple examples of this online.

6. Finally, you must keep track of the files that were changed and the number of changes made in each one. At the end of the process (when no more directories can be found from your starting point), you must print out a report. The report will simply list each changed file, along with the count of the changes in each. The files should be ordered/sorted on the number of changes, with the most heavily modified listed first. Note that you do not have to write your own sort algorithm. Instead, provides a sorting function called qsort, that can be used to sort arbitrary items. To use qsort, you must simply provide a comparison function that qsort can use (Java uses a similar logic for sorting objects).

i will send the rest part of the question , but i just need to get started. Can you please help?

In terms of your task, it is fairly easy to describe. You will be writing a simple search and replace application. Specifically, your job is to ('1) find a user-specified text string within a group of disk files, (2) modify those strings and update the original disk files, and then (3) provide a report that indicates what has been done. It will work as follows: 1. The application will take a single command argument. This argument will be interpreted as a text string. For example, if your program was c might enter replace.exe apple. Note that if you are using the Eclipse C/C++ plugin as your IDE, you can use a Run Configuration" to specify the command line argument. alled replace.exe, you 2. You will then open each of the files in the current directory. If you haven't done much programming with files and directories, it isn't especially difficult. That said, the facilities for doing so in C are somewhat more primitive than those in languages such as Java. First, you will want to make use of the functions associated with . As we discussed in class, these are the basic IO functions, and can be applied not only to the screen and keyboard, but to disk files as well (There are countless online examples of basic CI/O). Here, you will use functions for opening and closing files, reading and writing bytes/chars to and from files, and for checking to see to see if vou have reached the end of the file 3. In addition to opening and reading files, you must also be able to read the contents of the directory in order to see what files need to be checked (the current directory- "."). Basically, a directory is just a special type of file that contains a list of the files within it. So the idea is to just loop through the file list, and open and examine eaclh text file (for simplicity, all files used during testing will be text files with a .txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

Discuss how a psychological skills program might be evaluated.

Answered: 1 week ago