Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ques) write a program in c, which meets the following requirements. You will find it tedious to type lots of text into your program's stdin.

Ques) write a program in c, which meets the following requirements.

image text in transcribed

You will find it tedious to type lots of text into your program's stdin. The shell has a powertul tool to help with this: stream redirection. This allows you to route the stdin and stdout for a program away from the console and into a file. For example, if we have a program called hello that prints 'Hello world'in' on stdout, we can do this: $ ./hello myfile.tx This creates a new file myfile.txt. Anything written to stdout in the hello program is written to the file myfile.txt. To confirm this, inspect the contents of the file with cat: s cat myfile.txt Hello world! Similarly, we can take the contents of a file, and stream it into the standard input of our program. So if we have a program sort that reads lines from stdin, sorts them into lexical order then writes them on stdout, we can do this: Contents of file bcatles.txt john george ringo S sort sarted.txt S cat sorted.txt george paul ringo This is a very powerlul mechanism that is great for testing with lots of different inputs. It's much more convenient to redirect a file into stdin than to type many lines followed by ctrl.d over and over. Make sure you undersland file Here is a terse but good introduction to BASH shell programming, including a section on redirection Here is an task that will make you glad you know about shell redirection: Requirements Write a C program that counts the number of characters, words and lines read from standard input until EOF is reached. Assume the input is ASCIl text of any length. Every byte read from stdin counts as a character except EOF Words are defined as contiguous sequences of letters (a through z, A through Z) and the apostrophe', value 39 decimal) separated by any character outside these ranges. Lines are defined as contiguous sequences of characters separated by newline characters n). Characters beyond the final newline character will not be included in the line count. On reaching EOF, use this output command: printf( .%lu %lu %lu ', charcount, wordcount, linecount ): Where charcount, wordcount and linecount are all of type unsigned long int. You may need these large types to handle long documents. Guide You may find the standard library function getchar useful. Check it out onlin or read its manpage. There's a handy standard program called we that does a sirnilar job, but it does not match the requirements exactly (it is a little more clever about word boundaries and will sometimes count fewer words than our simple program). Your program should agree with we's character and line counts, as the logic for those is the sane. Escape characters This Q&A on StackOverflow gives advice on representing the apostrophe character using an escape sequence. StackOverflow is very useful indeed. Testing and submission Submit your solution as a complete program (i e. with a main) function) in a C source file called count.c

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What is a compiler?

Answered: 1 week ago