Answered step by step
Verified Expert Solution
Link Copied!

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. h file. The function is called from main function defined in main. c.
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 ** delete_comments (char ** input);
input is a dynamically allocated string of code segment containing some C comments
The function should
(n,\r,\t ), 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 de-allocate 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 '??O??'.
implementation.
image text in transcribed

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

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago