Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input

Write a C program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string REDACTED . You are essentially creating a tool for redacting, or censoring, blacklisted words. Think of the classified government memos with the important bits blacked out. 2. Given the same input file, report the number of characters and then number of words present in the text. Because we have not yet covered file I/O, routines for reading and writing strings to files will be provided. The routines come in the form of a pre-compiled object file and accompanying header file Required functionality: 1. Accept command line parameters for the following a) Input file name b) Output file name c) List of black listed words to be remove from the input file text See the Input/Output Requirements section for details on the format of your program inputs 2. The censoring functionality has the following requirements a) The text to censor is read from the input file specified on the command line. Use the readFromFile() function provided to do so b) In this text, look for and replace every instance of the blacklisted words provided on the command line with the word REDACTED c) Write the censored text to the output file specified on the command line. Use the writeToFile() function provided to do so You can assume following There will be no more than 20 blacklisted words input on the command line There will be no more than MAX_CHAR_COUNT/2 number of characters in the input file. This constant is specified in the fileUtils.h file 3. Before censoring the text from the input file a) Find the number of characters in the text (this includes spaces, newlines, or any valid character). Write the results to output file. b) Find the number of words in the text and write the result to the output file 4. You must use functions from the string library to manipulate the text 5. Your program must be split up into multiple files a) A .c file with all manipulation and count related function implementations b) A .h file with all macros and function definitions for the above .c file c) A .c file that contains your main and any other functions 6. A makefile to compile your program a) All of your source files should be compiled with c99 and the -Wall option b) An example will be provided Suggestions The following string library functions could be useful strlen strcpy strncpy strcat strncat strtok strstr You will need to include the fileUtils.h file in your code wherever you use the readFromFile() and writeToFile() functions You can use a diff tool to compare the file output from your program to the expected, correct output. There is a diff command available on linux. Input/Output Requirements: 1. The syntax for running your program should be programName input.txt output.txt word1 word2 word3 input.txt - File containing text to be censored output.txt - File where censored text and counts are written word1 word2 - The words that should be censored from the input text 2. The format of the output file should adhere to the following standard CHARACTER COUNT WORD COUNT CENSORED TEXT Each of these items is started on a new line. The censored text should have the same format as the original text, with only the blacklisted words being replaced with REDACTED

#include #include #include "fileUtils.h"

#define MAX_NUM_WORDS 20

int main(int argc, char* argv[]) { char* inputFilename = argv[1]; char* outputFilename = argv[2];

char str[MAX_CHAR_COUNT];

//Double check that the number of command line arguments matches //how many I expect () if(argc < 3) { printf("Missing input parameters "); printf("Program usage: %s ", argv[0]); return -1; }

/*read input file to string*/ int status = readFromFile(str, inputFilename); switch(status) { case FILE_OPEN_ERROR: printf("Error opening %s ", inputFilename); break; case FILE_READ_ERROR: printf("Error reading %s ", inputFilename); break; default: //display contents of file in terminal printf("Read From file %s: %s ", inputFilename, str); } /*Edit string by adding something to the beginning*/ strcat(str, " *** EDITED BY JOHN ***");

/*Write the edited string to the designated output file*/ status = writeToFile(str, outputFilename, OVERWRITE_FILE); switch(status) { case FILE_OPEN_ERROR: printf("Error opening %s ", inputFilename); break; case FILE_WRITE_ERROR: printf("Error reading %s ", inputFilename); break; case FILE_WRITE_INVALID_MODE: printf("Invalid write mode for %s ", inputFilename); break; default: printf("Wrote to %s ", outputFilename); }

/*Append a string to the end of the same file*/ if(writeToFile(" *** A SECOND EDIT BY JOHN ***", outputFilename, APPEND_FILE) == FILE_OK) printf("Wrote to %s ", outputFilename); else printf("There was some sort of problem writing to %s", outputFilename);

}

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

Step: 3

blur-text-image

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

Explain the steps involved in training programmes.

Answered: 1 week ago

Question

What are the need and importance of training ?

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago