Question

Write a program to read in the file below and count the number of sentences, and...

Write a program to read in the file below and count the number of sentences, and the number of each sentence terminators noted in the next statement. A sentence ends with a '.', ';', '?', or '!'.

The name of the file should be a command line parameter to your program called terminatorCounters.

Just a little confused on how to get started here.

the file is just a text file.

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

/*terminatorCounters.c*/
#include <stdio.h>

int main(int argc, char *argv[])
{
FILE *fp;
char *filename;
char ch;
int line_count = 1;
int terminator_count =0;
  
//Check if the argument has Filename
if (argc < 2)
{
printf("No file name in the command line argument");
return(0);
}
  
filename = argv[1];
printf("Name of the file: %s\n", filename);
  
// Opening the file in read only mode
fp = fopen(filename,"r");

// If file opened successfully, extract characters from file and store in character ch
if ( fp )
{
for ( (ch = fgetc(fp)); ch != EOF ; ch=getc(fp))
{
//Counting number of sentences
if (ch == '\n'){
line_count = line_count + 1;
}
//Counting number of sentence terminator
if ((ch == '.' || ch == '?' || ch == ';' || ch == '!')){
terminator_count = terminator_count + 1;
}
}
  
printf("Total number of sentences %d \n ", line_count);
printf("Total number of terminator characters %d \n ", terminator_count);
}
else
{
printf("Unable to open the file\n");
}
// Close the file
fclose(fp);
  
return(1);
}

Add a comment
Know the answer?
Add Answer to:
Write a program to read in the file below and count the number of sentences, and...
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
  • Write a C++ program that will count the number of words and vowels in a sentence....

    Write a C++ program that will count the number of words and vowels in a sentence. Create a bool function called isVowel that accepts a character as a parameter and returns a true if it’s a vowel (aeiou) and false otherwise. Create an int function named countVowels that will accept a string variable as a parameter and will return the number of vowels in it. Call the isVowel function as part of this process. Write an int function named countWords...

  • 12.13 (Count characters, words, and lines in a file) Write a program that will count the...

    12.13 (Count characters, words, and lines in a file) Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown in Figure 12.13 D Command Prompt exercise java Exercise12.13 Loan.java ile Loan.jaua has 1919 characters 10 words 71 lines lexercise Figure 12.13 The program displays the number of characters, words, and lines in the given file. This...

  • Hello! i need a program in C that uses FILE*! The instructions are below! Please dont...

    Hello! i need a program in C that uses FILE*! The instructions are below! Please dont copy paste another chegg post! Thank you! Will leave positive review! I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each...

  • IN PYTHON 3: Write a Python program to read the attached text file containing words, count...

    IN PYTHON 3: Write a Python program to read the attached text file containing words, count the occurrence of each unique word and store the words in alphabetical order in a text file listing the word and the total count of that word. You cannot use any advanced features such as dictionaries. The program requires user input to determine the name of the file. (example of the text file that needs to be read = for a brief moment I...

  • In C Programming Language, write a simple program to read one text file and print to...

    In C Programming Language, write a simple program to read one text file and print to screen all its text. Make use of the stderr and exit program statements should there not be only one text file identified on the command line. If successful then before fclose of the text file, use the fputs program statement to write a line "72 degrees Sunny light wind. Nice!\n". print the return code of fputs (should be zero). close and exit. Test program...

  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

  • C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :)...

    C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :) Use FILE I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each group of adjacent vowels (a, e, i, o, u,...

  • Write a C program to run on ocelot to read a text file and print it...

    Write a C program to run on ocelot to read a text file and print it to the display. It should optionally find the count of the number of words in the file, and/or find the number of occurrences of a substring, and/or take all the words in the string and sort them lexicographically (ASCII order). You must use getopt to parse the command line. There is no user input while this program is running. Usage: mywords [-cs] [-f substring]...

  • (Count the occurrences of words in a text file) Rewrite Listing 21.9 to read the text...

    (Count the occurrences of words in a text file) Rewrite Listing 21.9 to read the text from a text file. The text file is passed as a command-line argument. Words are delimited by white space characters, punctuation marks (, ; . : ?), quotation marks (' "), and parentheses. Count the words in a case-sensitive fashion (e.g., consider Good and good to be the same word). The words must start with a letter. Display the output of words in alphabetical...

  • Write a C function to count the number of sentences entered; assume a sentence ends in...

    Write a C function to count the number of sentences entered; assume a sentence ends in either a period, question mark, or exclamation point.The primary function should be named "sentences" and the secondary function "sentence_counter."

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