Question
In C language: Implement function char *delete_comments(char *input) that removes C comments from program stored at input . input variable points to dynamically allocated memory
In C language:
Implement function char *delete_comments(char *input) that removes C comments from program stored at input. input variable points to dynamically allocated memory (malloc, realloc, free). The function returns pointer to the polished program. You may allocate a new memory block for the output, or modify the content directly in the input buffer.
Youll need to process two types of comments:
-
Traditional block comments delimited by /* and */. These comments may span multiple lines. You should remove only characters starting from /* and ending to */ and for example leave any following newlines untouched.
-
Line comments starting with // until the newline character. In this case, newline character must also be removed.
The function calling delete_comments only handles return pointer from delete_ comments. It does not allocate memory for any pointers. One way to implement delete_comments function is to allocate memory for destination string. However, if new memory is allocated then the original memory in input must be released after use.
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