Question

//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

//I NEED THE PROGRAM IN C LANGUAGE!//

QUESTION:

I need you to write a 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”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Blacklist.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 256

char* rep_str(const char *s, const char *old, const char *new1)
{
char *ret;
int i, count = 0;
int newlen = strlen(new1);
int oldlen = strlen(old);

for (i = 0; s[i] != '\0'; i++)
{
if (strstr(&s[i], old) == &s[i])
{
count++;
i += oldlen - 1;
}
}
ret = (char *)malloc(i + count * (newlen - oldlen));
if (ret == NULL)
exit(EXIT_FAILURE);
i = 0;
while (*s)
{
if (strstr(s, old) == s) //compare the substring with the newstring
{
strcpy(&ret[i], new1);
i += newlen; //adding newlength to the new string
s += oldlen;//adding the same old length the old string
}
else
ret[i++] = *s++;
}
ret[i] = '\0';
return ret;
}

void main( unsigned int argc, unsigned char *argv[] )
{
FILE *src, *dst;
char b[MAX];
int count=0, j, w = 1;
  
if(argc<4){
    printf("\nInsufficient arguments\n");
   exit(0);
}
  
/* Two parameters -- use input and output files. */
if ( ( src = fopen( argv[1], "r" )) == NULL )
{
puts( "Can't open input file.\n" );
exit( 0 );
}
if ( ( dst = fopen( argv[2], "w" )) == NULL )
{
puts( "Can't open output file.\n" );
exit( 0 );
}
  
/* Copy one file to the next. */
while( ( fgets( b, MAX, src ) ) != NULL )
{
fputs(rep_str(b,argv[3],"REDACTED"), dst );
}
  
char ch;
  
while((ch=fgetc(dst))!=EOF) {
   count++;
   if(isspace(ch)||ch=='\t'||ch=='\n')
   w++;
}
    
printf("\nNumber of Words : %d\n",w);
printf("\nNumber of characters : %d\n",count);

/* All done, close up shop. */
fclose( src );
fclose( dst );
}

//Output

:〈Users\G priya Dars hní〈Documents〉blk -exe input.txt outpt.txt was umber of Words: 345 umber of characters 3813 aic

Also check your input and output text files for complete result

Add a comment
Know the answer?
Add Answer to:
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Programming question For this exercise, you will receive two string inputs, which are the names...

    C++ Programming question For this exercise, you will receive two string inputs, which are the names of the text files. You need to check if the input file exists. If input file doesn't exist, print out "Input file does not exist." You are required to create 4 functions: void removeSpace (ifstream &inStream, ofstream &outStream): removes white space from a text file and write to a new file. If write is successful, print out "Text with no white space is successfully...

  • Write a C program which computes the count of the prime and perfect numbers within a...

    Write a C program which computes the count of the prime and perfect numbers within a given limit Land U, representing the lower and upper limit respectively. Prime numbers are numbers that have only 2 factors: 1 and themselves (1 is not prime). An integer number is said to be perfect number if its factors, including 1 (but not the number itself), sum to the number. Sample Inputi: 1 100 Sample Outputs: Prime: 25 Perfect: 2 Sample Input2: 101 10000...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • python Create a program to open a text file for reading, find the maximum number in...

    python Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...

  • java find and replace code pls help me We write code that can find and replace...

    java find and replace code pls help me We write code that can find and replace in a given text file. The code you write should take the parameters as command line arguments: java FindReplace -i <input file> -f "<find-string>" -r "<replace-string> -o <output file> *question mark(?) can be used instead of any character. "?al" string an be sal ,kal,val *In addition, a certain set of characters can be given in brackets.( "kng[a,b,f,d,s]ne" string an be kngane,hngbne,kangfne,kangdne,kangsne So, all you...

  • Hi, I need help with my comp sci assignment. The parameters are listed below, but I...

    Hi, I need help with my comp sci assignment. The parameters are listed below, but I am having trouble generating the number of occurrences of each word. Please use a standard library. Read in the clean text you generated in part 2 (start a new cpp file). Create a list of all the unique words found in the entire text file (use cleanedTextTest.txt for testing). Your list should be in the form of an array of structs, where each struct...

  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

  • Write a C Program that: - Creates an input file (input.txt) - Take user inputted integer...

    Write a C Program that: - Creates an input file (input.txt) - Take user inputted integer for number of lines in the input file - accepts inputted text from command line to the input file (input.txt) - saves and closes file. (input.txt) - reopens and displays the newly inputted contents of the file

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT