user-0 提问: [小白]用c写了个css自动格式化的工具，遇到一些问题。。

回复:
user: user-1
content: 仅供参考：//有字符串 //1_22_333,,4444__55555,_666666 //需要解析为 //1 //22 //333 //_ //4444 //55555 //666666 #include <stdio.h> char s[]="1_22_333,,4444__55555,_666666"; char c,*p,*p1; int st; void main() {     st=0;     p=s;     while (1) {         c=*p;         if (0==c) {             switch (st) {             case 1:printf("_\n");    break;             case 2:printf("%s\n",p1);break;             }             break;//         }         switch (st) {         case 0:                  if ('_'==c) {                            st=0;}             else if (','==c) {                            st=1;}             else             {p1=p;                       st=2;}         break;         case 1:                  if ('_'==c) {                            st=1;}             else if (','==c) {printf("_\n");              st=1;}             else             {p1=p;                       st=2;}         break;         case 2:                  if ('_'==c) {*p=0;printf("%s\n",p1);*p=c;st=0;}             else if (','==c) {*p=0;printf("%s\n",p1);*p=c;st=1;}             else             {                            st=2;}         break;         }         p++;     } } //1 //22 //333 //_ //4444 //55555 //666666

user: user-0
content: 抱歉才看见，之前的问题解决了，我研究一下您的代码，晚上结帖哈哈哈，感谢大佬~~~

user: user-0
content: 目前可以将上图这种被压缩过没有空格换行的min.css文件转换为下图这模样。。但是我不想要 tag 名和 hover，focus等等之间的空格啊啊啊。。 心态崩了。。

user: user-0
content: 源码如下： #include <stdio.h> #include <string.h>  int main(int argc, char const *argv[]) {     FILE *srcfile, *aimfile;     char srcpath[100] = "tmp/";     char aimpath[100] = "res/";     char srcfilename[] = "bootstrap-reboot.min.css";     char aimfilename[] = "bootstrap-reboot.css";     char prechar, curchar, sufchar;     int brace = 0;              // '{' counts. For computing indent.     int isAnnotation = 0;     int iscolon = 0;            // to make a ':' is a line; solve something like 'font-family: SFMono-Regular, "Liberation Mono", "Courier New", monospace;'      strcat(srcpath, srcfilename);     strcat(aimpath, aimfilename);      srcfile = fopen(srcpath, "r");     aimfile = fopen(aimpath, "w");      curchar = fgetc(srcfile);     prechar = curchar;     do {         sufchar = fgetc(srcfile);         fputc(curchar, aimfile);    // only put curchar into new file          // ignore annotation         if (curchar == '*' && sufchar == '/') {             isAnnotation = 0;         }         if (prechar != '*' && curchar == '/' && sufchar == '*') {             isAnnotation = 1;         }         if (isAnnotation) {             curchar = sufchar;             continue;         }         // put an enter between '*/' and classname         if (prechar == '*' && curchar == '/') {             fputc('\n', aimfile);         }            if (sufchar == '{') {  // put a space between classname and '{'             fputc(' ', aimfile);         } else if (sufchar == '}') {             if (curchar != '}' && curchar != ';') { // avoid unnecessary line break                 fputc('\n', aimfile);             }             brace--;        // a '{}' is over, indent will reduce             for (int i = 0; i < brace; i++) {                 fputc('\t', aimfile);             }         }            if (curchar == '{' || curchar == ';') {             if (curchar == '{'){                 brace++;        // one '{' makes its items one more indent             }             if (curchar == ';') {                 iscolon = 0;    // the ':' is over.             }             fputc('\n', aimfile);             for (int i = 0; i < brace; i++) {                 fputc('\t', aimfile);             }         } else if (curchar == '}') {             iscolon = 0;    // the ':' is over.             fputc('\n', aimfile);             if (curchar == '}') {                 for (int i = 0; i < brace; i++) {                     fputc('\t', aimfile);                 }             }         } else if (curchar == ',') {             if (iscolon) {                 fputc(' ', aimfile);             }             else {                 fputc('\n', aimfile);             }         } else if (curchar == ':' && prechar != ':' && sufchar != ':') {             fputc(' ', aimfile);    // put a space behind ':', except something like '::after'             iscolon = 1;            // ':' is begin         }           prechar = curchar;         curchar = sufchar;     } while (curchar != EOF);          fclose(srcfile);     fclose(aimfile);     return 0; }