#include
int main()
{
char buf[128];
char *p = buf;
char *point_flag = NULL;
printf("请输入一个小数:");
gets(buf);
printf("%s\n", buf);
while(*p != '\0' && *p != '\n')//找到你输入的结束符,回车符或结束符,并做一些合法性判断
{
//判断是否是合法小数
if(*p == '.')
{
if(point_flag != NULL)
{
printf("无效小数!\n");
return -1;
}
point_flag = p;
}
else if(*p > '9' || *p < '0') //
{
if(point_flag == 0)
printf("输入有误!\n");
return -2;
}
p++;
}
p--;
while(p != buf && *p == '0')//过滤掉结尾的0
{
p--;
}
*(p+1) = 0;
if(point_flag != NULL)
{
printf("小数值为:%s\n", point_flag+1);
}else{
printf("没有小数值!\n");
}
//getchar();
return 0;
}
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
void main(void){
char n[20],*p=n,*pt;
int m=0;
printf("Type a Floating point Numbers...\nn=");
scanf("%s",n);
while(*p++ != '.');
pt=p;printf("%s\n",pt);
while(*pt) pt++;
while(*--pt=='0');
while(p<=pt) (m*=10) += *p++ - '0';
printf("By %s the result is %d.\n",n,m);
}
我给你说思路,具体自己写。把输入用字符串存。然后查找点,后面当作新的字符串,判断最后几位是0,是'0'就赋值'\0'否则输出
仍然没有解决