Strip block comments: Difference between revisions
Content added Content deleted
m (apply polish) |
m (→{{header|C}}: prettier) |
||
Line 142: | Line 142: | ||
=={{header|C}}== |
=={{header|C}}== |
||
<lang C>#include<stdio.h> |
<lang C>#include <stdio.h> |
||
#include<string.h> |
#include <string.h> |
||
#include<stdlib.h> |
#include <stdlib.h> |
||
char*ca="/*",*cb="*/"; |
char *ca = "/*", *cb = "*/"; |
||
int al=2,bl=2; |
int al = 2, bl = 2; |
||
⚫ | |||
void pause(){ |
|||
⚫ | |||
puts("Press Enter"); |
|||
⚫ | |||
getchar(); |
|||
} |
|||
if (f != NULL) { |
|||
⚫ | |||
⚫ | |||
FILE*f; |
|||
l = ftell(f); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
rewind(f); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
fread(s, 1, l, f); |
|||
⚫ | |||
if(s)fread(s,1,l,f); |
|||
} |
|||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
} |
} |
||
void stripcomments(char*s){ |
void stripcomments(char *s) { |
||
char *a, *b; |
|||
int len = strlen(s) + 1; |
|||
⚫ | |||
while ((a = strstr(s, ca)) != NULL) { |
|||
⚫ | |||
⚫ | |||
if (b == NULL) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
} |
|||
} |
} |
||
int main(int argc,char**argv){ |
int main(int argc, char **argv) { |
||
char *s = "input.txt"; |
|||
⚫ | |||
⚫ | |||
s=loadfile(s); |
|||
⚫ | |||
⚫ | |||
s = loadfile(s); |
|||
if (argc == 4) { |
|||
⚫ | |||
al = strlen(ca = argv[2]); |
|||
} |
|||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
pause(); |
|||
puts(s); |
|||
return 0; |
|||
}</lang> |
}</lang> |
||
;Usage: |
;Usage: |
||
Line 205: | Line 206: | ||
} |
} |
||
</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |