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 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:
#include
#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
/*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 USER ***");
/*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);
}
i wrote these 2 functions:
#include
i am stuck on how to manipulate words and how to add them into main. Need help ASAP its due in 6 hrs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
