C语言老出错
#include"stdio.h"#include"stdlib.h"
#include"math.h"
#define M 450 /*待处理数据的长度*/
#define G 4 /*结构元素的长度*/
#define N 40000 /*代表无穷大*/
double M_max(double f[]) /*取极大值*/
{
int i;
double a;
a=f[0];
for(i=1;i<M;i++)
{
if(f[i]>a)
a=f[i];
}
return(a);
} /* 极大值函数结束*/
double M_min(double f[]) /*取极小值*/
{
int i;
double a;
a=f[0];
for(i=1;i<M;i++)
{
if(f[i]<a)
a=f[i];
}
return a;
} /* 极小值函数结束*/
double R_shift(double f[],int k) /* 右移函数*/
{int i;
double f1[M];
if(k>0)
for(i=M-1;i>=0;i--)
{
if(i>k)
f1[i]=f[i-k];
else
f1[i]=-N;
}
else if(k<0)
{
for(i=0;i<M;i++)
if(i<=(k+M))
f1[i]=f[i-k];
else
f1[i]=-N;
}
else
{
for(i=0;i<M;i++)
f1[i]=f[i];
}
return f1;
} /* 右移函数结束*/
double dilate(double f[],int g[],int c) /* 膨胀函数*/
{
int c1,c2,i,j;
double f1[G][M],f2[M];
double f3[G];
c1=1-c;
c2=G-c;
for(i=0;i<G;i++)
{
f2=R_shift(f,c1);
for(j=0;j<M;j++)
{f1[i][j]=f2[j]+g[i];}
c1=c1+1;
}
for(i=0;i<M;i++)
{
for(j=0;j<G;j++)
{f3[j]=f1[j][i];}
f2[i]=M_max(f3);
}
return(f2);
} /* 膨胀函数结束*/
double L_shift(double f[],int k) /* 左移函数*/
{
int i;
double f1[M];
if(k>0)
{for(i=M-1;i>=0;i--)
{if(i>k)
f1[i]=f[i-k];
else
f1[i]=N;
}}
else if(k<0)
{for(i=0;i<M;i++)
{
if(i<=k+M)
f1[i]=f[i-k];
else
f1[i]=N;
}}
else
{
for(i=0;i<M;i++)
f1[i]=f[i];
}
return f1;
} /* 左移函数结束*/
double erode(double f[],int g[],int c) /*腐蚀函数*/
{
int c1,c2,i,j;
double f2[M];
double f1[G][M];
double f3[G];
c1=1-c;
c2=G-c;
for(i=0;i<M;i++)
{f2=L_shift(f,c1);
for(j=0;j<M;j++)
{f1[i][j]=f2[j]-g[i];}
c1=c1+1;
}
for(i=0;i<M;i++)
{
for(j=0;j<G;j++)
{f3[j]=f1[j][i];}
f2[i]=M_min(f3);
}
return(f2);
} /* 腐蚀函数结束*/
void main() /* 主函数*/
{
int i;
double y[M],y1[M],y2[M],y3[M];
double y11[M],y12[M],y21[M],y22[M];
int g1[G]={1,1,0,0},g2[G]={0,0,1,1};
int c1,c2;
c2=G,c1=1;
for(i=0;i<50;i++)
y[i]=1;
for(i=50;i<150;i++)
y[i]=5;
for(i=150;i<300;i++)
y[i]=8;
for(i=300;i<450;i++)
y[i]=3;
y11=dilate(y,g1,c1);
y12=erode(y,g1,c1);
y21=erode(y,g2,c2);
y22=dilate(y,g2,c2);
for(i=1;i<450;i++)
{y1[i]=y11[i]+y12[i];
y2[i]=y21[i]+y22[i];
y3[i]=y2[i]-y1[i];
}
}
运行老出错:
--------------------Configuration: sum1 - Win32 Debug--------------------
Compiling...
zhuhanshu.c
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(57) : error C2115: 'return' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(57) : warning C4172: returning address of local variable or temporary
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(69) : error C2115: '=' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(69) : error C2106: '=' : left operand must be l-value
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(80) : error C2115: 'return' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(80) : warning C4172: returning address of local variable or temporary
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(107) : error C2115: 'return' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(107) : warning C4172: returning address of local variable or temporary
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(119) : error C2115: '=' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(119) : error C2106: '=' : left operand must be l-value
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(130) : error C2115: 'return' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(130) : warning C4172: returning address of local variable or temporary
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(149) : error C2115: '=' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(149) : error C2106: '=' : left operand must be l-value
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(150) : error C2115: '=' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(150) : error C2106: '=' : left operand must be l-value
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(151) : error C2115: '=' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(151) : error C2106: '=' : left operand must be l-value
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(152) : error C2115: '=' : incompatible types
D:\CCStudio_v3.3\MyProjects\lianxi1\zhuhanshu.c(152) : error C2106: '=' : left operand must be l-value
执行 cl.exe 时出错.
sum1.exe - 1 error(s), 0 warning(s)