<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 文字轉聲明: 編寫程序將特定格式的輸入轉換為C語言聲明

          文字轉聲明: 編寫程序將特定格式的輸入轉換為C語言聲明

          作者: 時間:2016-11-22 來源:網(wǎng)絡 收藏
          一. 程序功能
          編寫程序特定格式的輸入轉換為C語言聲明.
          二. 程序源碼
          #include
          #include
          #include
          #define MAXTOKEN 100
          enum {NAME, PARENS, BRACKETS};
          int tokentype;
          char token[MAXTOKEN];
          char name[MAXTOKEN];
          char datatype[MAXTOKEN];
          char out[1000];
          int p_getch(void);
          void p_ungetch(int);
          int main(void)
          {
          int type, lasttype;
          char temp[MAXTOKEN];
          printf("Please input(ctrl+z to quit)n");
          while (gettoken() != EOF)
          {
          strcpy(out, token);
          lasttype = 0;
          while ((type = gettoken()) != n)
          {
          if (type == NAME)
          {
          sprintf(temp, "%s %s", token, out);
          strcpy(out, temp);
          }
          else
          {
          if (lasttype == *)
          {
          sprintf(temp, "(%s)", out);
          strcpy(out, temp);
          }
          if (type == PARENS || type == BRACKETS)
          strcat(out, token);
          else if (type == *)
          {
          sprintf(temp, "*%s", out);
          strcpy(out, temp);
          }
          else
          printf("Error: Invalid input at %s!n", token);
          }
          lasttype = type;
          }
          printf("%sn",out);
          }
          return 0;
          }
          int gettoken(void)
          {
          int c;
          char *p = token;
          while ((c = p_getch()) == || c == t)
          ;
          if (c == ()
          {
          if ((c = p_getch()) == ))
          {
          strcpy(token, "()");
          return tokentype = PARENS;
          }
          else
          {
          p_ungetch(c);
          return tokentype = (;
          }
          }
          else if (c == [)
          {
          for (*p++ = c; (*p++ = p_getch()) != ];)
          ;
          *p = 看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();