70,023
社区成员




用字符串
仅供参考:
#include <stdio.h>
#include <string.h>
char s[80];
double d;
char c;
int main() {
while (1) {
printf("Input a double:");fflush(stdout);
rewind(stdin);
fgets(s,80,stdin);
if (strlen(s)>20) {
printf("Input too long(>20)!\n");
continue;
}
if (2==sscanf(s,"%lf%c",&d,&c)) {
if ('\n'==c) {
printf("%lg is a double.\n",d);
break;
}
}
if ('\n'==s[strlen(s)-1]) s[strlen(s)-1]=0;
printf("\"%s\" is NOT a double!\n",s);
}
return 0;
}