有个c程序编译时出现点错误需要大家帮忙,谢谢!
#include <windows.h>#include <math.h>
#include <stdio.h>
#define WINDOW_WIDTH 400
#define WINDOW_HEIGHT 400
char* g_szApplicationName="圆覆盖矩形(矩形覆盖)";
char* g_szWindowClassName="LinrenWindowClass";
struct mypoint{
double x,y;
}myp[200];
struct myrect{
double x,y;
double x2,y2;
double x3,y3;
}myr[200];
/**只用修改这里******************************/
#define PARM_R 24.1
#define PARM_L 233.5
#define PARM_D 197.4
/******************************只用修改这里**/
int n,n2;
double r=PARM_R,l=PARM_L,d=PARM_D;
double at,sq2,x,y;
double a,e;
#undef PARM_R
#undef PARM_L
#undef PARM_D
char str[100];
void fun(){
int cl,cd,i,j;
x=(double(WINDOW_WIDTH)-l)/2.0;
y=(double(WINDOW_HEIGHT)-d)/2.0;
sq2=sqrt(2.0);
a=sq2*r;
at=(a-r)/sq2;
cl=(int)(l/a);
cd=(int)(d/a);
n=0;
for(i=0;i<cl;i++){
for(j=0;j<cd;j++){
myp[n].x=x+a*i;
myp[n].y=y+a*j;
n++;
}
}
e=(int)(r+r+1e-15);
n2=0;
double t1,t2,t3,t4;
int kd;
t1=l-cl*a;
t2=sqrt((r+r)*(r+r)-t1*t1);
t3=d-cd*a;
t4=sqrt((r+r)*(r+r)-t3*t3);
if(t1<t4){
kd=(int)(l/t4);
myr[n2].x=x+kd*t4;
myr[n2].y=y+cd*a;
myr[n2].x2=x+(kd+1)*t4;
myr[n2].y2=y+d;
myr[n2].x3=myr[n2].x-(r-t4/2.0);
myr[n2].y3=myr[n2].y-(r-t3/2.0);
n2++;
}else if(t3<t2){
kd=(int)(d/t2);
myr[n2].x=x+cl*a;
myr[n2].y=y+kd*t2;
myr[n2].x2=x+l;
myr[n2].y2=y+(kd+1)*t2;
myr[n2].x3=myr[n2].x-(r-t1/2.0);
myr[n2].y3=myr[n2].y-(r-t2/2.0);
n2++;
}else{
kd=(int)(l/t4);
myr[n2].x=x+kd*t4;
myr[n2].y=y+cd*a;
myr[n2].x2=x+(kd+1)*t4;
myr[n2].y2=y+d;
myr[n2].x3=myr[n2].x-(r-t4/2.0);
myr[n2].y3=myr[n2].y-(r-t3/2.0);
n2++;
kd=(int)(d/t2);
myr[n2].x=x+cl*a;
myr[n2].y=y+kd*t2;
myr[n2].x2=x+l;
myr[n2].y2=y+(kd+1)*t2;
myr[n2].x3=myr[n2].x-(r-t1/2.0);
myr[n2].y3=myr[n2].y-(r-t2/2.0);
n2++;
}
kd=(int)(d/t2);
for(i=0;i<kd;i++){
myr[n2].x=x+cl*a;
myr[n2].y=y+i*t2;
myr[n2].x2=x+l;
myr[n2].y2=y+(i+1)*t2;
myr[n2].x3=myr[n2].x-(r-t1/2.0);
myr[n2].y3=myr[n2].y-(r-t2/2.0);
n2++;
}
kd=(int)(l/t4);
for(i=0;i<kd;i++){
myr[n2].x=x+i*t4;
myr[n2].y=y+cd*a;
myr[n2].x2=x+(i+1)*t4;
myr[n2].y2=y+d;
myr[n2].x3=myr[n2].x-(r-t4/2.0);
myr[n2].y3=myr[n2].y-(r-t3/2.0);
n2++;
}
sprintf(str,"总数:%d",n+n2);
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
static HBRUSH hbrush=(HBRUSH)GetStockObject(NULL_BRUSH);
static HPEN newpen=CreatePen(PS_SOLID,1,RGB(255,0,0));
static HPEN oldpen=NULL;
switch(msg){
case WM_CREATE:
{
PAINTSTRUCT ps;
int i;
BeginPaint(hwnd,&ps);
SelectObject(ps.hdc,hbrush);
for(i=0;i<n;i++){
Ellipse(ps.hdc,(int)(myp[i].x-at+0.5),(int)(myp[i].y-at+0.5),
(int)(myp[i].x-at+e+0.5),(int)(myp[i].y-at+e+0.5));
Rectangle(ps.hdc,(int)(myp[i].x+0.5),(int)(myp[i].y+0.5),
(int)(myp[i].x+a+0.5),(int)(myp[i].y+a+0.5));
}
for(i=0;i<n2;i++){
Ellipse(ps.hdc,(int)(myr[i].x3+0.5),(int)(myr[i].y3+0.5),
(int)(myr[i].x3+e+0.5),(int)(myr[i].y3+e+0.5));
Rectangle(ps.hdc,(int)(myr[i].x+0.5),(int)(myr[i].y+0.5),
(int)(myr[i].x2+0.5),(int)(myr[i].y2+0.5));
}
oldpen=(HPEN)SelectObject(ps.hdc,newpen);
Rectangle(ps.hdc,(int)(x+0.5),(int)(y+0.5),(int)(x+l+0.5),(int)(y+d+0.5));
SelectObject(ps.hdc,oldpen);
TextOut(ps.hdc,20,20,str,strlen(str));
EndPaint(hwnd,&ps);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
int i;
BeginPaint(hwnd,&ps);
SelectObject(ps.hdc,hbrush);
for(i=0;i<n;i++){
Ellipse(ps.hdc,(int)(myp[i].x-at+0.5),(int)(myp[i].y-at+0.5),
(int)(myp[i].x-at+e+0.5),(int)(myp[i].y-at+e+0.5));
Rectangle(ps.hdc,(int)(myp[i].x+0.5),(int)(myp[i].y+0.5),
(int)(myp[i].x+a+0.5),(int)(myp[i].y+a+0.5));
}
for(i=0;i<n2;i++){
Ellipse(ps.hdc,(int)(myr[i].x3+0.5),(int)(myr[i].y3+0.5),
(int)(myr[i].x3+e+0.5),(int)(myr[i].y3+e+0.5));
Rectangle(ps.hdc,(int)(myr[i].x+0.5),(int)(myr[i].y+0.5),
(int)(myr[i].x2+0.5),(int)(myr[i].y2+0.5));
}
oldpen=(HPEN)SelectObject(ps.hdc,newpen);
Rectangle(ps.hdc,(int)(x+0.5),(int)(y+0.5),(int)(x+l+0.5),(int)(y+d+0.5));
SelectObject(ps.hdc,oldpen);
TextOut(ps.hdc,20,20,str,strlen(str));
EndPaint(hwnd,&ps);
}
break;
case WM_DESTROY:
DeleteObject(hbrush);DeleteObject(newpen);DeleteObject(oldpen);
PostQuitMessage(0);break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR szCmdLine,int iCmdShow){
HWND hWnd;
WNDCLASSEX winclass;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hInstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = g_szWindowClassName;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winclass)){
MessageBox(NULL,"RegisterClassEx Error!","error",0);return 0;
}
hWnd=CreateWindowEx(NULL,
g_szWindowClassName,
g_szApplicationName,
WS_OVERLAPPEDWINDOW,
GetSystemMetrics(SM_CXSCREEN)/2-WINDOW_WIDTH/2,
GetSystemMetrics(SM_CYSCREEN)/2-WINDOW_HEIGHT/2,
WINDOW_WIDTH,
WINDOW_HEIGHT,
NULL,NULL,hInstance,NULL);
if(!hWnd){
MessageBox(NULL,"CreateWindowEx Error!","error",0);return 0;
}
fun();
ShowWindow(hWnd, iCmdShow);UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);DispatchMessage(&msg);
}
return msg.wParam;
}