Question

In: Computer Science

Write a program that echoes the input one word per line. Remove all punctuation and all...

Write a program that echoes the input one word per line. Remove all punctuation and all blank lines.

Code must be written in C. Not c++ or c#.

Input: Use the following Ogden Nash poem to test your program.

The Parsnip

The parsnip, children, I repeat,

Is simply an anemic beet.

Some people call the parsnip edible;

Myself, I find this claim incredible

Note: There are multiple blank lines before and after the title.

There may be multiple blank spaces or tabs between words.

There may be multiple blank lines in the text

Use getchar() and putchar().

You may not use any string handling functions in this program. The only functions you may use are input and output functions, such as getchar and putchar

Output: One word per line left justified. (No punctuation, no blank lines between words)

Solutions

Expert Solution

SOLUTION-
I have solve the problem in C code with comments and screenshot for easy understanding :)

CODE-

//c code
#include <stdio.h>
#include <conio.h>
int main() {
char story[1024];
int i = 0, j = 0, flag = 0,k,c;
FILE *fptr,*fptr2;
//get input from file
fptr = fopen("sample.txt","r");
while (1)
{
story[i] = fgetc(fptr);
if (story[i++] == EOF)
{
story[i] = '\0';
break;
}
}
//prints in output file
fptr2=fopen("result.txt","w");

for (j = 0; j < i; ++j)
{
if ((story[j] <= 'z' && story[j] >= 'a') || (story[j] <= 'Z' && story[j] >= 'A') || (story[j] <= '9' && story[j] >= '0'))
{
fputc(story[j],fptr2);
  
flag = 1;
}
else
{
if (flag==1)
{
fputc('\n',fptr2);
flag = 0;
}
}
}


fclose(fptr);
fclose(fptr2);

return 0;
}

--------------------------------------------------------------------------

Input file=sample.txt

The Parsnip

The parsnip, children, I repeat,

Is simply an anemic beet.

Some people call the parsnip edible;

Myself, I find this claim incredible.

---------------------------------------------------------------------------

Output file=result.txt

The
Parsnip
The
parsnip
children
I
repeat
Is
simply
an
anemic
beet
Some
people
call
the
parsnip
edible
Myself
I
find
this
claim
incredible


SCREENSHOT-

Input file=sample.txt

Output file=result.txt


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Write a Python program that reads a file, input by the user, containing one word/token per...
Write a Python program that reads a file, input by the user, containing one word/token per line with an empty line between sentences. The program prints out the longest word found in the file along with its length.
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
Write a program that will read in from input file one line at a time until...
Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas and periods....
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
C++ Write a word search program that searches an input data file for a word specified...
C++ Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of grammatical characters in the input data file. Your program must do this by providing the following function: void processFile(ifstream &inFile, string wordSearch, int &wordCount, int &grammaticalCount); void processFile(ifstream &inFile, string wordSearch, int &wordCount, int...
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
Write an assembly program that lets the user to input only the word MASM and displays...
Write an assembly program that lets the user to input only the word MASM and displays invalid input for any other user inputs.
Write a java program that will take a line of input and go through and print...
Write a java program that will take a line of input and go through and print out that line again with all the word numbers swapped with their corresponding numeric representations (only deal with numbers from one to nine). Sample runs might look like this: Please enter a line of input to process: My four Grandparents had five grandchildren My 4 grandparents had 5 grandchildren without array and methods.
Write in javaScript: User input 5 words in one input, and print out the longest word.
Write in javaScript: User input 5 words in one input, and print out the longest word.
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT