Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void remove_cmmnt(char *s) //essentially the two nested if statements are to skip over the text that contains comments
  4. {
  5. int i,j;
  6. for(i=j=0; s[j] ; ) //if s of j has a value the body will execute, then do the test again etc.
  7. {
  8. if(s[j]=='/' && s[j+1] && s[j+1]=='/') //if the current character is '/' and the following character is '/', run the for statement.
  9. for(j+=2; s[j] && s[j++]!='\n'; ) //the place in the array becomes the character after the the '/', then moves along the array
  10. ; //until it reaches a newline character. j then increments by 1
  11.  
  12. else if(s[j]=='/' && s[j+1] && s[j+1]=='*') //if the current character is '/' and the following character is '*', run the for statement.
  13. for(j+=2; s[j] && s[++j] && (s[j-1]!='*' || s[j]!='/' || !j++); ) //the place in the array becomes the character after the '*'.
  14. ; //the place in the array is incremented. Then if the current character
  15. //and the previous character are '*/', increment j by 1
  16. else
  17. s[i++]=s[j++]; //copies the value of s of j to s of i, then increments i and j
  18. }
  19. s[i]='\0';
  20. }
  21.  
  22. int main()
  23. {
  24. char s[]="/*123***/Hello // Cross\n World /* **NachLeCoders";
  25. remove_cmmnt(s);
  26. puts(s);
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement