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 #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 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 #include #define N 1000 int count_characters(char *s); int count_words(char *s); int count = 0; char ch[N] = "hello world!"; int main(void) { int num = count_characters(ch); int word_count = count_words(ch); printf("number of characters: %d ", num); printf("the amount of words is: %d ", word_count); return 0; } int count_characters(char *s) { while(*s!= '\0') { count++; s++; } return count; } int count_words(char *s) { int num_of_words =0; int length = 0; if(s==NULL) { return 0; } else { while(*s) { if (*s ==' ') { length=0; } else if(++length ==1) { num_of_words++; } s++; } } return num_of_words; }

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!