C Program to remove comments from a line

Write a program to remove a comment starting with /* and ending with */ in a statement, which is entered by the user. If the input does not contain a comment, the program should leave the statement as it is.
Input: int i; /*declare integer variable i*/
Output: int i;
Input: int i;
Out: int i;
Your program should include the following function:
void remove_comment(char *s1, char *s2);
The function expects s1 to point to a string containing the input as a string and stores the output to the string pointed by s2.
1) Name your program remove.c.
2) Assume input is no longer than 100 characters. Assume the input contains no more than one /*…*/ comment.
3) The remove_comment function should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the function.
4) To read a line of text, use the read_line function (the pointer version) in the lecture notes.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • File Format: .c