Chinaunix首页 | 论坛 | 博客
  • 博客访问: 119741
  • 博文数量: 41
  • 博客积分: 1695
  • 博客等级: 上尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-21 22:50
文章分类

全部博文(41)

文章存档

2010年(1)

2007年(23)

2006年(17)

我的朋友

分类: C/C++

2007-01-09 00:27:22

//07.01.09
//Guo R.H

#include
#include
#include

#define CHAR 1
#define NUMBER 0
#define BUFSIZE 10

char buf[BUFSIZE];
int bufp = 0;
int getch()
{
    return bufp == 0?getchar():buf[--bufp];
}

void ungetch(int c)
{
    buf[bufp++] = c;
}


int gettop(char s[])
{
    char c;
    int i=0;
    s[0] = c = getch();
    if(c == EOF)
        return c;
    if (!isdigit(c))
    {
        while(!isdigit( s[++i] = c = getch() )  && c != EOF)
            ;
        ungetch(c);
        s[i] = '\0';
        return CHAR;
    }
    if(isdigit(c))
    {
        while(isdigit( s[++i] = c = getch() ))
            ;
        ungetch(c);
        s[i] = '\0';
        return NUMBER;
    }
}

int main()
{
    char ch[10][50], tc[50];
    double a[5];
    int flag, i=0, j, k=0, l;
    while((flag = gettop(tc)) != EOF)
    {
        j=0;
        l=0;
        if(flag == CHAR)
        {    
            while(ch[i][l++] = tc[j++])
                ;
            i++;
        }
        else
            a[k++] = atof(tc);
    }
    for(j=0; j        printf("%lf ", a[j]);
    for(j=0; j        printf("%s ", ch[j]);

    return 0;
}

阅读(808) | 评论(0) | 转发(0) |
0

上一篇:atof字符转浮点

下一篇:全排列

给主人留下些什么吧!~~