Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use c and Unix to finish this program, thanks! 3) (20 marks) Write a C program named a6q3.c which removes C-style comments of the
Please use c and Unix to finish this program, thanks!
3) (20 marks) Write a C program named a6q3.c which removes C-style comments of the form "/*...*/" from the input. The program must read standard input and produce standard output. Any character outside of a comment should be copied as it is. It is recommended that you use functions getchar and putchar for this copying. The comments must be skipped in copying with exception of the new-line characters. If any new-line characters are included in a comment they must be copied to the output. This is done in order to preserve line positions of the text and the total number of lines from the input to the output The program must not store text unnecessarily, meaning that it must print characters as soon as possible after reading them. Sometimes it may need to wait with a character before printing; for example, after reading a slash character it needs to wait if the next character is asterisk or not to decide whether the comment is starting or not. Remember that you need to handle only the comments of the form "/*.*/", but not line comments starting with The input may end while the program is reading a comment, in which case, you should print the following line at the end COMMENT NOT FINISHED> ending with a newline character. It is recommended that you use a finite automaton in processing, such as the following not / not S_START S SLASH S COMMENT S_ASTERISK not / and not * notand not/ You can control the state of your program using the above diagram. You still need to decide what characters to output in each state as the program reads the inputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started