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 translates an English word into a Pig Latin word. Input ONE, and...
Write a program that translates an English word into a Pig Latin word. Input ONE, and ONLY one, word from the user, and then output its translation to Pig Latin. The rules for converting a word to Pig Latin follow. The general form for converting a word is to remove the first letter. Then append to the end of the word a hyphen, followed by the first letter that was removed, followed by "ay". For example, "robot" becomes "obot-ray" and...
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....
5. Write a program that prints all numbers between 27 and 78, one number per line....
5. Write a program that prints all numbers between 27 and 78, one number per line. 6. In questions 6,7 the following list is used: [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12] 7. Using “for” loop, write program that finds the smallest number in the list. 8. Using “for” loops, calculate arithmetic mean of all numbers in the list. Do not use built-in function in Python. 9. For this question envision you are creating a dummy alert to help the doctor determine if patient needs a...
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT