假定输入的字符串中只包含字母和*号。请编写程序,删除字符串中除了尾部的*号之外的其他*号。不得使用

假定输入的字符串中只包含字母和*号。请编写程序,删除字符串中除了尾部的*号之外的其他*号。不得使用C语言的字符串函数。例如,若字符串中的内容为:****A*BC*DEF*G******,删除后,字符串中的内容为:ABCDWFG******。求数据结构版的程序,急急急!!!

就这样吧:

#include <stdio.h>

int main()
{
    char *strDemo = "****A*BC*DEF*G******";
    int iPos = 0;
    char cLast = ' ';

    while (strDemo[iPos] != '\0') {
        if (strDemo[iPos] != '*') {
            putchar(strDemo[iPos]);
            cLast = strDemo[iPos];
        }
        iPos++;
    }

    while (--iPos >= 0)
        if (strDemo[iPos] == '*')
            putchar('*');
        else
            break;

    return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答