Question
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 BLACKLISTED
2. Given the same input file, report the number of characters and then number of words present in the text.
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
You can assume following:
There will be no more than 20 blacklisted words input on the command line
There will be no more than 1500 number of characters in the input file.
You must use functions from the string library to manipulate the text and your program must be split up into multiple files
The following string library functions could be useful strlen strcpy strncpy strcat strncat strtok strstr
You will need to include the utils.h file in your code wherever you use the readFromFile() and writeToFile() functions
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
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
utils.h file :
#ifndef FILEUTILS_H #define FILEUTILS_H
#define MAX_CHAR_COUNT 3000
//Output file open modes #define OVERWRITE_FILE 0 #define APPEND_FILE 1
//File operation return codes #define FILE_OK 0 #define FILE_OPEN_ERROR -1 #define FILE_READ_ERROR -2 #define FILE_WRITE_ERROR -3 #define FILE_WRITE_INVALID_MODE -4
/* ReadFromFile() - Reads the contents of a file into a string * Inputs: * char* contents - String where the contents of file are store. * This string is assumed to have a maximum length of MAX_CHAR_COUNT * char* filename - String containing the filename to open for reading * * Returns an int specifying the success or failure of the operation. * See return codes defined above */ int readFromFile(char* contents, char* filename);
/* WriteToFile() - Writes a string to a file * Inputs: * char* contents - String to be written to a file * char* filename - String containing the filename to open for writing * int mode - Specifies how to open file for write. OVERWRITE_FILE will cause previous writes to be deleted. APPEND_FILE will write contents to the end of the file, preserving previous writes. * * Returns an int specifying the success or failure of the operation. * See return codes defined above. */ int writeToFile(char* contents, char* filename, int mode);
#endif //FILEUTILS_H
I will definitely rate so please be correct I need help :(
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