新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 文字轉(zhuǎn)聲明: 編寫(xiě)程序?qū)⑻囟ǜ袷降妮斎朕D(zhuǎn)換為C語(yǔ)言聲明

        文字轉(zhuǎn)聲明: 編寫(xiě)程序?qū)⑻囟ǜ袷降妮斎朕D(zhuǎn)換為C語(yǔ)言聲明

        作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò) 收藏
        一. 程序功能
        編寫(xiě)程序特定格式的輸入轉(zhuǎn)換為C語(yǔ)言聲明.
        二. 程序源碼
        #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 = 主站蜘蛛池模板: 河东区| 工布江达县| 松原市| 会理县| 松滋市| 武安市| 石棉县| 通化市| 鹿邑县| 临洮县| 鄂伦春自治旗| 平乡县| 穆棱市| 富阳市| 县级市| 八宿县| 得荣县| 鹤峰县| 成都市| 庐江县| 道真| 黑水县| 绍兴市| 屏东县| 新丰县| 扎鲁特旗| 策勒县| 龙海市| 西安市| 黄浦区| 蒙山县| 禹州市| 吴堡县| 山西省| 洛扎县| 肃北| 文安县| 武宁县| 荥阳市| 潼南县| 冷水江市|