欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

實(shí)現(xiàn)去除c語言注釋的小工具

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

去除C代碼中的注釋,
1. 單行注釋//;
2. 多行注釋/**/;
3. 單行注釋以“\”結(jié)尾則下一行也為注釋;
4. 字符串中的注釋不處理。
說是C語言,但其實(shí)所有C語系的都可以,比如Java。


小工具:去除C語言注釋 

復(fù)制代碼 代碼如下:

#include <stdio.h>

int main(int argc, char* argv[]) {
  enum {
    literal,
    single,
    multiple,
    string
  } mode = literal;
  char last = 0, current;

  while ((current = getchar()) != EOF) {
    switch (mode) {
    case single: {
      if (last != '\\' && (current == '\n' || current == '\r')) {
        putchar(current);
        current = 0;
        mode = literal;
      }
    } break;
    case multiple: {
      if (last == '*' && current == '/') {
        current = 0;
        mode = literal;
      }
    } break;
    case string: {
      if (last == '\\') {
        putchar(last);
        putchar(current);
      } else if (current != '\\') {
        putchar(current);
        if (current == '"') {
          mode = literal;
        }
      }
    } break;
    default: {
      if (last == '/') {
        if (current == '/') {
          mode = single;
        } else if (current == '*') {
          mode = multiple;
        } else {
          putchar(last);
          putchar(current);
        }
      } else if (current != '/') {
        putchar(current);
        if (current == '"') {
          mode = string;
        }
      }
    } break;
    }
    last = current;
  }

  return 0;
}

測試代碼

復(fù)制代碼 代碼如下:

#include <stdlib.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
// not show\
not show\
not show
// not show
/* not show */
    int is; // not show
    int/* not show */ ms; /* not show */
    double ds; // not show\
    not show\
    not show
    double dm; /* ...
    not show
    not show */ float fs; /**
                           * now show
                           */
    float/**/ fm;
    char cs[] = "aaa // /***/";
    char cm1[] = /* not show */"hello*/";
    char cm2[] = "/*redraiment"/* not show */;
    /* printf("http://///"); */
    return EXIT_SUCCESS;
}

處理后的代碼

復(fù)制代碼 代碼如下:

#include <stdlib.h>
#include <stdio.h>

int main (int argc, char *argv[])
{

 

    int is;
    int ms;
    double ds;
    double dm;  float fs;
    float fm;
    char cs[] = "aaa // /***/";
    char cm1[] = "hello*/";
    char cm2[] = "/*redraiment";

    return EXIT_SUCCESS;
}

上一篇:數(shù)據(jù)結(jié)構(gòu)順序表操作示例

欄    目:C語言

下一篇:C/C++獲取目錄下的文件列表信息

本文標(biāo)題:實(shí)現(xiàn)去除c語言注釋的小工具

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3756.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有