C程序找错,急啊
#include"stdio.h"double GetReal(char *s); /*用来实atof的函数*/
int ten_n(int);
void main()
{
char s[]=" -3454e-3";
double n;
n=GetReal(s);
printf("%f",n);
}
double GetReal(char *s)
{
int i,i1,j,k,s1[100],s2[100];
double n,n1,n2;
char *p;
p=s;
while(*p==' ')
p++;
if(*p=='-')
{
p++;
i=0;
while(*p!='e'&&*p!='E'&&*p!='.')
{
s1[i++]=(int)(*(p++)-48);
printf("%d",s1[i-1]);
}
printf("\n");
if(*p=='e'||*p=='E')
{
p++;
i1=0;
if(*p=='-')
{
p++;
do
{
s2[i1++]=(int)(*(p++)-48);
}while(*p!='\0');
k=0;n1=0;
for(j=i-1;j>=0;j--)
n1+=s1[k++]*ten_n(j);
k=0;n2=0;
for(j=i1-1;j>=0;j--)
n2+=s2[k++]*ten_n(j);
printf("n2=%d\n",n2); /疑问在这里:这里n2=3才对,怎么运算出来n2=0呢?/
n2=-n2;
n=n1+(double)ten_n(n2);
return n;
}
}
}
}
int ten_n(int n)
{
int s=1,i;
for(i=1;i<=n;i++)
s*=10;
return s;
}