双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

float与Int的问题

woshibianbian woshibianbian 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"

/*
Template designed by RuPeng.com. Please visit http://www.rupeng.com for more information
如鹏网(http://www.rupeng.com)大学生计算机学习社区,提供大量免费视频学习教程,提供个性化一对一学习指导
*/
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}

return FALSE;
}

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
return TRUE;
}

BOOL isfloat(TCHAR *a)
{
float b = atof(a);//为什么这里用float后,程序不能帅选是数字,但是用int就可以了?
TCHAR c[256];
wsprintf(c,"%d",b);
if(strcmp(c,a)!=0)
{
return FALSE;
}
else
{
return TRUE;
}
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
TCHAR str1[256],str2[256];
GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1));
GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2));
if(isfloat(str1)==FALSE)
{
MessageBox(hwnd,TEXT("错误"),TEXT("1单元非法字符"),NULL);
return;

}
if(isfloat(str2)==FALSE)
{
MessageBox(hwnd,TEXT("错误"),TEXT("2单元非法字符"),NULL);
return;
}
float str1temp = atof(str1);
float str2temp = atof(str2);

float str3temp = str1temp-str2temp;
TCHAR a[256];
sprintf(a,"%f",str3temp);
SetDlgItemText(hwnd,IDC_EDIT3,a);
}
break;
default:
break;
}
}

void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
woshibianbian
C语言 70,039 成员 243,237 内容