fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void remove_comment(char *s1, char *s2) {
  5.  
  6. for(int in_comment=0; *s1 ; s1++){ //loops through array until null value
  7. if(!in_comment && *s1 == '/' && s1[1]=='*') { //if array has '/' stored
  8. in_comment=1;
  9. s1++;
  10. }
  11. else if (in_comment) {
  12. if (*s1=='*' && s1[1]=='/') {
  13. in_comment = 0;
  14. s1++;
  15. }
  16. }
  17. else *s2++=*s1;
  18. }
  19. *s2='\0';
  20. }
  21.  
  22. int main()
  23. {
  24. char s1[101]; //declares arrays up to 100 in length with room for null character
  25. char s2[101];
  26.  
  27. printf("Enter a comment: "); //enter a comment
  28. gets(s1); // saves comment to array
  29. printf ("'%s'\n",s1);
  30.  
  31. remove_comment(s1,s2); //calls function
  32. printf ("-> '%s'\n",s2);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 2160KB
stdin
comment /* comment  */ yeah!
stdout
Enter a comment: 'comment /* comment  */ yeah!'
-> 'comment  yeah!'