I need some assistence with this C program Any help is appre
I need some assistence with this C program. Any help is appreciated.
1. (60 points) 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, theprogram should leave the statement as it is.
Input: int i; /*declare integer variable i*/
 Output: int i;
Input: int i;
 Out: int i;
The 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 storesthe 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 ofarray subscripting). In other words, eliminate the loop index variables and all useof the [] operator in the function.
4) To read a line of text, use the read_line function (the pointer version).
Solution
//remove.c
#include <stdio.h>
 #include <string.h>
void remove_comment(char *s1, char *s2)
 {
     for(int c=0; *s1 ; s1++)
     {
       // found start of comment
       if(!c && *s1 == \'/\' && *(s1+1)==\'*\')
       {
           c=1;  
           s1++;
       }
       // found end of comment
       else if (c)
       {  
           if (*s1==\'*\' && *(s1+1)==\'/\')
           {  
               c = 0;
               s1++;
           }
       }
       // if not comment the directly copy the character
       else *s2++ = *s1;     
     }
     // end string
     *s2=\'\\0\';
 }
int main()
 {
char s1[101];
 char s2[101];
printf(\"Enter a statement: \");
 fgets(s1, 100, stdin);
remove_comment(s1,s2);
printf(\"%s\", s2);
return 0;
 }


