Advertisement
Guest User

Untitled

a guest
May 4th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. char *remove_comments(char *input)
  2. {
  3.    
  4.     int pituus = strlen(input);
  5.     char* buffer = malloc((pituus+1) * sizeof(char));
  6.     int i = 0;
  7.     int a = 0;
  8.    
  9.     while(input[i] != '\0') {
  10.        
  11.         if (input[i] == '/' && input[i+1] == '*' ) {
  12.             i+=2;
  13.             while (input[i] != '*' || input[i+1] != '/')  {
  14.                 i++;
  15.             }
  16.             i+=2;
  17.         }
  18.        
  19.         else if (input[i] == '/' && input[i+1] == '/') {
  20.             i++;
  21.             while(input[i] != '\n') {
  22.                 i++;
  23.             }
  24.             i++;
  25.         }
  26.         buffer[a] = input[i];
  27.         i++;
  28.         a++;
  29.     }
  30.  
  31.     free(input);
  32.     buffer[a] = '\0';
  33.     return buffer;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement