Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implementation The exercise template is composed of multiples of files. You are required to implement your solution in source. c . The functions your are
Implementation
The exercise template is composed of multiples of files. You are required to implement your solution in source. c
The functions your are going to implement are already declared in source. file. The function is called from main function defined in main.
Background
detects
line comments that start with and end with
character including
block comments that starts with and ends with
Description
In this task, you are required to implement a function that polishes a C code segment by removing all the comments from it
The complete function declaration is
char deletecomments char input;
input is a dynamically allocated string of code segment containing some comments
The function should
nrt after should not be removed.
ii remove the line comments starting with until and including the newline character
iii. return a pointer to the string of polished code segment.
The function implementation should assume that the caller will deallocate the pointer returned by the function. The input pointer is not freed by the caller.
Implementation
Both types of comments start with specific two character sequences. Thus, you must check current and previous characters are one of the comment type start sequence.
When you detect the start of the comment, you should check whether the detected comment type is terminated.
When no comment start sequence is detected, you should copy the text to a destination string character array
When the input string reaches to the termination character, the destination string must be terminated and returned.
Important
Therefore, if your function allocates memory for the output destination string but does NOT free input, you will get Valgrind errors and your points will be reduced.
Hint
Remember that in C language strings are null terminated. Therefore, every string must have enough space for the termination character
implementation.
Step 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