Last active
August 29, 2015 14:18
-
-
Save tomcha/d86fb5c5339d2db95157 to your computer and use it in GitHub Desktop.
1-23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #define MAXSTRINGS 1000 | |
| // | |
| //ファイル操作はまだ学習してないので、Cのソースをcatとパイプで受け取る前提 | |
| int main(){ | |
| int c; | |
| int i = 0; | |
| int j; | |
| int qflg; // '-> 1, "-> 2 | |
| int eflg; // normal ->0, // -> 1, /* -> 2 | |
| char str[MAXSTRINGS]; | |
| char newstr[MAXSTRINGS]; | |
| while((c = getchar()) != EOF){ | |
| str[i++] = c; | |
| } | |
| // printf("first:%s", str); | |
| // printf("----------------------\n"); | |
| i = 0; | |
| j = 0; | |
| qflg = 0; | |
| eflg = 0; | |
| for(;i < MAXSTRINGS; i++){ | |
| // printf("q:%d e:%d ch:%c\n", qflg, eflg, str[i]); | |
| if(qflg > 0){ | |
| if(qflg == 1 && str[i] == '\''){ | |
| qflg = 0; | |
| }else if(qflg == 2 && str[i] == '"'){ | |
| qflg = 0; | |
| } | |
| newstr[j++] = str[i]; | |
| }else if(str[i] == '\''){ | |
| qflg = 1; | |
| newstr[j++] = str[i]; | |
| }else if(str[i] == '"'){ | |
| qflg = 2; | |
| newstr[j++] = str[i]; | |
| }else if(eflg > 0){ | |
| if(eflg == 2 && str[i] == '*' && str[i+1] == '/'){ | |
| eflg = 0; | |
| i++; | |
| }else if(eflg == 1 && str[i] == '\n'){ | |
| eflg = 0; | |
| newstr[j++] = str[i]; | |
| } | |
| }else if(str[i] == '/' && str[i+1] == '/'){ | |
| eflg = 1; | |
| i++; | |
| }else if(str[i] =='/' && str[i+1] == '*'){ | |
| eflg = 2; | |
| i++; | |
| }else{ | |
| newstr[j++] = str[i]; | |
| } | |
| } | |
| printf("%s", newstr); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment