There is nothing wrong with this problem, my mistake is that I can't read the question.
Another thing to note is that floating-point numbers exist-0
1#include <stdio.h>2#include <ctype.h>3#include <math.h>4 #defineMax_str_len 10 + 55 DoubleStrtodouble (Charstr[]) {6 intState=0;7 DoubleSUM1 =0.0;8 Doublesum2 =0.0;9 intk=1;Ten intDigited=0; One intfuhao=1; A if(!str[0])return 0; - for(intI=0; str[i];i++){ - if(digited==0&&str[i]=='-') the { -Digited=1; -Fuhao =-1; - } + if(digited==0&&str[i]=='+'){ -Digited=1; +Fuhao =1; A } at if(IsDigit (Str[i])) { -Digited=1; - if(!state) sum1=Ten*sum1 +str[i]-'0'; - Elsesum2+= (POW (0.1, k++)) * (str[i]-'0'); - } - Else if(str[i]=='.'){ inDigited=1; -State=1; to } + } - returnfuhao* (sum1 +sum2); the } * $ intMain ()Panax Notoginseng { - CharS[max_str_len]; the while(Gets (s)! =NULL) +printf"%lg\n", strtodouble (s)); A return 0; the}
Yamada Stust OJ problem B: Write function: String to Double (II) (Append Code)