Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago