当前位置: 代码迷 >> C语言 >> 新手求助,HELP~~~`
  详细解决方案

新手求助,HELP~~~`

热度:176   发布时间:2008-04-10 22:26:22.0
新手求助,HELP~~~`
程序要求:在对话框中输入数字类型的字符串,转化为相应的数字并输出.
以下是我的程序:
#include<stdio.h>
#include<iostream.h>
#include<ctype.h>
int lineno=1;
int tokenval=NULL;
float tokenval1=0;
int i;
void lexan()
{
    char t;
    while(1){
        t=getchar();
        if(t==' '||t=='\t');
        else if(t=='\n')
            lineno=lineno+1;
        else if(t>='0'&&t<='9'){
            tokenval=t-'0';
            t=getchar();
            while(t>='0'&&t<='9'){
                tokenval=tokenval*10+t-'0';
                t=getchar();
            }
            if(t!='.'&&t!='e'&&t!='E'){
                ungetc(t,stdin);
                printf("%d\n",tokenval);
                break;
            }
            if(t=='.'){
                t=getchar();
                int linenum1=0;
                while(t>='0'&&t<='9'){
                tokenval1=tokenval1*10+t-'0';
                linenum1=linenum1+1;
                t=getchar();
                }
                for(i=linenum1;i>0;i--){
                        tokenval1=tokenval1/10;
                    }
                if(t!='e'&&t!='E'){
                    ungetc(t,stdin);
                    tokenval1=(float)(tokenval)+tokenval1;
                    printf("%f\n",tokenval1);
                    break;
                }
            }printf("%f\n",tokenval1);
            if(t=='e'||t=='E'){
                t=getchar();
                int tokenval2=0;
                while(t>='0'&&t<='9'){
                    tokenval2=tokenval2*10+t-'0';
                    t=getchar();
                }
                for(i=tokenval2;i>0;i--){
                    tokenval1=tokenval1*10;
                }
                printf("%f\n",tokenval1);
                break;
            }
        }
        else{
            tokenval=NULL;
            printf("%d",t);
        }
    }
}

void main(){
    lexan();
}

但是输入带e的字符串是输出错误,希望大家能帮帮我.先谢谢了.
搜索更多相关的解决方案: HELP  

----------------解决方案--------------------------------------------------------
字也太小了吧。O近视啊!
----------------解决方案--------------------------------------------------------
  相关解决方案