关于函数数组指针混乱之战-qq群求助+解答

来源:互联网 发布:网络直播唱痒的女的 编辑:程序博客网 时间:2024/06/05 06:15

Will(95367158)  16:56:05
有谁指点一下下面的程序啊
Will(95367158)  16:56:14
#include "math.h"


#define   pi 3.1416
#define   Point 1024


float x1r[Point],*x1i[Point]={0};
float x2r[Point],x2i[Point]={0};

void multi( int N,float *x1,float *x2);
void put_in(int N,float *x1,float *x2);
void FFT(int N,float *xr,float *xi,int ntype);


//数据处理程序
void dataprocess()
{

 int  i;


//上游信号fft变换后取共轭
 void put_in(Point,float *x1r,float *x1i);
 void FFT(Point,float *x1r,float *x1i,1);
 for (i=0;i<Point;i++)
  {
    *x1i[i]=-*x1i[i];
  }

//下游信号fft变换
 void put_in(Point,float *x2r,float *x2i);
 void FFT(Point,float *x2r,float *x2i,1);
 
//上下游信号相乘后取IFFT变换
 void multi(Point,float *x1r,float *x2r);
 void FFT(Point,float *x1r,float *x1i, -1);

}
 
//输入子程序
void put_in(int N,float *x1,float *x2)
{
 int i;
 float p=3.1416;

 for(i=0;i<N;i++)
 {
  x1[i]=cos(p*i*i/N);
  x2[i]=0;
  }
}


 void multi( int N,float *x1,float *x2)

  int  j,i=0;
  float t;
  for(j=0;j<1024;j++)
   {
    t=x1[i];
t=x2[i]*t;
x1[i]=t;
i++;
   }
}
Will(95367158)  16:56:32
编译后
Will(95367158)  16:56:50
[2812_DataProcess.c] "E:\ccs3.3\C2000\cgtools\bin\cl2000" -g -fr"C:/Users/will/Desktop/2812 project ngguan_flowmeter_6/Debug" -d"_DEBUG" -d"LARGE_MODEL" -ml -v28 -@"../Debug.lkf" "2812_DataProcess.c"
"2812_DataProcess.c", line 36: error: expected a type specifier
"2812_DataProcess.c", line 37: error: expected a type specifier
"2812_DataProcess.c", line 37: error: expected a type specifier
"2812_DataProcess.c", line 44: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 44: error: expected a type specifier
"2812_DataProcess.c", line 45: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 45: error: expected a type specifier
"2812_DataProcess.c", line 45: error: expected a type specifier
"2812_DataProcess.c", line 48: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 48: error: expected a type specifier
"2812_DataProcess.c", line 49: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 49: error: expected a type specifier
"2812_DataProcess.c", line 49: error: expected a type specifier
13 errors detected in the compilation of "2812_DataProcess.c".

>> Compilation failure

Compile Complete,
  13 Errors, 0 Warnings, 0 Remarks.

Will(95367158)  16:57:11
哪位大侠指导一下
Will(95367158)  16:57:20
想了好久,改不动了
Will(95367158)  17:00:11
void dataprocess()就是这个函数很多错误,查了指针数组的书,不知道怎么办了
往最后的森林(627515898)  17:11:41
变换函数调用前面加VOID啥意思
Will(95367158)  17:12:40
就是不返回任何值
往最后的森林(627515898)  17:13:25
- -这个我知道,你在main里面还加算是什么
Will(95367158)  17:15:42
没有main啊
往最后的森林(627515898)  17:16:00
噢 是dataprocess
Will(95367158)  17:16:25
我是数组与数组之间的一些运算
Will(95367158)  17:16:39
不需要返回值的,最终都存在数组中
Will(95367158)  17:16:49
那些数值
往最后的森林(627515898)  17:18:36
你函数调用和参数传递有问题,对于数组和指针仔细看看吧
Will(95367158)  17:19:54
我看过了,就是看了书实在搞不懂才上来请教高手
往最后的森林(627515898)  17:21:22
x1i前面为什么要加个*?
Will(95367158)  17:21:55
 *x1i[i]=-*x1i[i];
Will(95367158)  17:22:10
如果不加又多报一条错误
Will(95367158)  17:22:16
就14条了
Will(95367158)  17:22:26
不信你可以编译一下的,ccs里
往最后的森林(627515898)  17:22:39
- -!我是说在float定义数组的时候
Will(95367158)  17:23:13
恩,就是在那里不这样定义就多报一条错误
往最后的森林(627515898)  17:24:09
这是一个地方!
你调用void函数,前面就不要void的,就像返回int的函数,你还会这么写吗
往最后的森林(627515898)  17:24:47
调用函数参数传递 还在参数前面加个float* 又是什么情况?
Will(95367158)  17:25:37
是哈,这样就定义指针数组了
往最后的森林(627515898)  17:26:43
为啥要定义指针数组
往最后的森林(627515898)  17:27:08
数组名不就是数组的首地址么
Will(95367158)  17:27:27
那个去掉void编译还是13个错误
往最后的森林(627515898)  17:27:37
因为还有其他错误- -
Will(95367158)  17:27:41
恩,数组我承认定义错了
往最后的森林(627515898)  17:28:26
void put_in(Point,float *x1r,float *x1i);
改成
void put_in(Point,x1r,x1i);
往最后的森林(627515898)  17:28:35
void去掉
往最后的森林(627515898)  17:28:53
前面定义x1i的*也去掉
Will(95367158)  17:29:12
我试一下
往最后的森林(627515898)  17:29:25
FFT函数一样~
Will(95367158)  17:29:42
[2812_DataProcess.c] "E:\ccs3.3\C2000\cgtools\bin\cl2000" -g -fr"C:/Users/will/Desktop/2812 project ngguan_flowmeter_6/Debug" -d"_DEBUG" -d"LARGE_MODEL" -ml -v28 -@"../Debug.lkf" "2812_DataProcess.c"
"2812_DataProcess.c", line 36: error: expected a type specifier
"2812_DataProcess.c", line 37: error: expected a type specifier
"2812_DataProcess.c", line 37: error: expected a type specifier
"2812_DataProcess.c", line 40: error: operand of "*" must be a pointer
"2812_DataProcess.c", line 40: error: operand of "*" must be a pointer
"2812_DataProcess.c", line 44: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 44: error: expected a type specifier
"2812_DataProcess.c", line 45: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 45: error: expected a type specifier
"2812_DataProcess.c", line 45: error: expected a type specifier
"2812_DataProcess.c", line 48: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 48: error: expected a type specifier
"2812_DataProcess.c", line 49: error: declaration may not appear after executable statement in block
"2812_DataProcess.c", line 49: error: expected a type specifier
"2812_DataProcess.c", line 49: error: expected a type specifier
15 errors detected in the compilation of "2812_DataProcess.c".

>> Compilation failure

Compile Complete,
  15 Errors, 0 Warnings, 0 Remarks.
Will(95367158)  17:30:07
fft不能去的
往最后的森林(627515898)  17:30:13
别急着编译- -
Will(95367158)  17:30:30

void FFT(int N,float*xr,float*xi,int ntype)//ntype=1----DFT
                                           //ntype=-1----IDFT

 int i,j,k,n,nv2,nml,l,le,lel,ip,sign=-1;
 float tr,ti,pi,ur,ui,wr,wi,ain;
 if(ntype<0)sign=1;
 n=N/2<<1;    
 nv2=n>>1;    //nv2=N/2
 nml=n-1;
 j=0;
 for(i=0;i<nml;i++) //  nm1=N-1 此处为倒位排序
 {
   if(i<j){ tr=xr[j];
            ti=xi[j];
xr[j]=xr[i];
xi[j]=xi[i];
xr[i]=tr;
xi[i]=ti;
           }
   k=nv2;
   while(i>=k){j-=k;
               k=k>>1;
  }
   j+=k;
 }

 pi=4.0*atan(1.0);
  for(l=1;l<N/2;l++) //蝶形运算
  {   
      le=l<<1;
  lel=le/2;
  ur=1.;
  ui=0.;
  wr=cos(pi/lel);
  wi=sign*sin(pi/lel);
  for(j=0;j<lel;j++)
      {
 for(i=j;i<n;i+=le)
 { ip=i+lel;
    tr=xr[ip]*ur-xi[ip]*ui;
ti=xr[ip]*ui+xi[ip]*ur;
xr[ip]=xr[i]-tr;
            xi[ip]=xi[i]-ti;
            xr[i]=xr[i]+tr;
            xi[i]=xi[i]+ti;
 }
 tr=ur*wr-ui*wi;
 ti=ur*wi-ui*wr;
 ur=tr;
 ui=ti;
   }
  }
 if(ntype>0) return;
 ain=1./n;
 for(i=0;i<n;i++)
    {xr[i]=xr[i]*ain;
 xi[i]=xi[i]*ain;
}

 return;

}


Will(95367158)  17:30:43
这是fft的
Will(95367158)  17:30:50
编译没有错误的
往最后的森林(627515898)  17:30:59
void FFT(Point,float *x1r,float *x1i,1);
改成
FFT(Point,x1r,x1i,1);

往最后的森林(627515898)  17:31:11
后面的一样
往最后的森林(627515898)  17:31:25
我说的是在dataprocess函数里面
Will(95367158)  17:31:32
我试试
往最后的森林(627515898)  17:31:46
我说的都是在dataprocess函数里面
往最后的森林(627515898)  17:32:16
然后是那个for循环 datarpocess里面
往最后的森林(627515898)  17:32:36
你想干嘛
Will(95367158)  17:32:57
就是那个数组里的数换成相反数
往最后的森林(627515898)  17:33:12
*都去掉
Will(95367158)  17:34:56
 put_in(Point,float *x1r,float *x1i)和 multi( int N,float *x1,float *x2)
Will(95367158)  17:34:58

Will(95367158)  17:36:59

#include "math.h"


#define   pi 3.1416
#define   Point 1024


float x1r[Point],x1i[Point]={0};
float x2r[Point],x2i[Point]={0};

void multi( int N,float *x1,float *x2);
void put_in(int N,float *x1,float *x2);
void FFT(int N,float *xr,float *xi,int ntype);


//数据处理程序
void  dataprocess()
{

 int  i;


//上游信号fft变换后取共轭
 void put_in(Point,float *x1r,float *x1i);
 void FFT(Point,float x1r,float x1i,1);
 for (i=0;i<Point;i++)
  {
    x1i[i]=-x1i[i];
  }

//下游信号fft变换
 void put_in(Point,float *x2r,float *x2i);
 void FFT(Point,float x2r,float x2i,1);
 
//上下游信号相乘后取IFFT变换
 void multi(Point,float *x1r,float *x2r);
 void FFT(Point,float x1r,float x1i, -1);

}
 
//输入子程序
void put_in(int N,float *x1,float *x2)
{
 int i;
 float p=3.1416;

 for(i=0;i<N;i++)
 {
  x1[i]=cos(p*i*i/N);
  x2[i]=0;
  }
}


 void multi( int N,float *x1,float *x2)

  int  j,i=0;
  float t;
  for(j=0;j<1024;j++)
   {
    t=x1[i];
t=x2[i]*t;
x1[i]=t;
i++;
   }
}
Will(95367158)  17:37:11
改成这样了,可还是14个错误
往最后的森林(627515898)  17:38:42
哎 我说了半天你一点也没明白~~
Will(95367158)  17:39:21
我不是按你说的改了吗
Will(95367158)  17:40:43

Will(95367158)  17:40:47
忘记去void了
往最后的森林(627515898)  17:41:35
#include "math.h"


#define   pi 3.1416
#define   Point 1024


float x1r[Point],x1i[Point]={0};
float x2r[Point],x2i[Point]={0};

void multi( int N,float *x1,float *x2);
void put_in(int N,float *x1,float *x2);
void FFT(int N,float *xr,float *xi,int ntype);


//数据处理程序
void  dataprocess()
{

 int  i;


//上游信号fft变换后取共轭
 put_in(Point,x1r,x1i);
 FFT(Point,x1r,x1i,1);
 for (i=0;i<Point;i++)
  {
    x1i[i]=-x1i[i];
  }

//下游信号fft变换
put_in(Point,x2r,x2i);
FFT(Point,x2r,x2i,1);
 
//上下游信号相乘后取IFFT变换
multi(Point,x1r,x2r);
FFT(Point,x1r,x1i, -1);

}
 
//输入子程序
void put_in(int N,float *x1,float *x2)
{
 int i;
 float p=3.1416;

 for(i=0;i<N;i++)
 {
  x1[i]=cos(p*i*i/N);
  x2[i]=0;
  }
}


 void multi( int N,float *x1,float *x2)

  int  j,i=0;
  float t;
  for(j=0;j<1024;j++)
   {
    t=x1[i];
t=x2[i]*t;
x1[i]=t;
i++;
   }
}
Will(95367158)  17:48:17
[2812_DataProcess.c] "E:\ccs3.3\C2000\cgtools\bin\cl2000" -g -fr"C:/Users/will/Desktop/2812 project ngguan_flowmeter_6/Debug" -d"_DEBUG" -d"LARGE_MODEL" -ml -v28 -@"../Debug.lkf" "2812_DataProcess.c"
"2812_DataProcess.c", line 36: error: expected an expression
"2812_DataProcess.c", line 36: error: expected an expression
"2812_DataProcess.c", line 37: error: expected an expression
"2812_DataProcess.c", line 37: error: expected an expression
"2812_DataProcess.c", line 44: error: expected an expression
"2812_DataProcess.c", line 44: error: expected an expression
"2812_DataProcess.c", line 45: error: expected an expression
"2812_DataProcess.c", line 45: error: expected an expression
"2812_DataProcess.c", line 48: error: expected an expression
"2812_DataProcess.c", line 48: error: expected an expression
"2812_DataProcess.c", line 49: error: expected an expression
"2812_DataProcess.c", line 49: error: expected an expression
12 errors detected in the compilation of "2812_DataProcess.c".

>> Compilation failure

Compile Complete,
  12 Errors, 0 Warnings, 0 Remarks.
Will(95367158)  17:48:32
按照你的我改后
Will(95367158)  17:54:07
有木有高手指点一下
Will(95367158)  17:54:13
感激不尽啊
往最后的森林(627515898)  17:55:20
36行是哪一行
Will(95367158)  17:56:07
//上游信号fft变换后取共轭 35行
往最后的森林(627515898)  17:58:18
好吧  这代码我拿到VC下编译 没有错误
Will(95367158)  17:58:35

Will(95367158)  17:58:44
那到底咋回事呢
Will(95367158)  17:58:47

往最后的森林(627515898)  18:00:04
剩下的错误 我觉得基本上应该是中英文标点之类的错误
往最后的森林(627515898)  18:02:01
你把#define   Point 1024  改成 const int Point=1024;
Will(95367158)  18:04:13
好像也不行
Will(95367158)  18:04:21
我再找找
Will(95367158)  18:05:27
[2812_DataProcess.c] "E:\ccs3.3\C2000\cgtools\bin\cl2000" -g -fr"C:/Users/will/Desktop/2812 project ngguan_flowmeter_6/Debug" -d"_DEBUG" -d"LARGE_MODEL" -ml -v28 -@"../Debug.lkf" "2812_DataProcess.c"
"2812_DataProcess.c", line 20: error: expression must have a constant value
"2812_DataProcess.c", line 20: error: expression must have a constant value
"2812_DataProcess.c", line 21: error: expression must have a constant value
"2812_DataProcess.c", line 21: error: expression must have a constant value
"2812_DataProcess.c", line 36: error: expected an expression
"2812_DataProcess.c", line 36: error: expected an expression
"2812_DataProcess.c", line 37: error: expected an expression
"2812_DataProcess.c", line 37: error: expected an expression
"2812_DataProcess.c", line 44: error: expected an expression
"2812_DataProcess.c", line 44: error: expected an expression
"2812_DataProcess.c", line 45: error: expected an expression
"2812_DataProcess.c", line 45: error: expected an expression
"2812_DataProcess.c", line 48: error: expected an expression
"2812_DataProcess.c", line 48: error: expected an expression
"2812_DataProcess.c", line 49: error: expected an expression
"2812_DataProcess.c", line 49: error: expected an expression
16 errors detected in the compilation of "2812_DataProcess.c".

>> Compilation failure

Compile Complete,
  16 Errors, 0 Warnings, 0 Remarks.
往最后的森林(627515898)  18:09:26
[Untitled1.c] "C:\CCStudio_v3.3\C2000\cgtools\bin\cl2000" -g -pdsw225 -fr"C:/programme/aa/Debug" -d"_DEBUG" -d"LARGE_MODEL" -ml -v28 -@"programme/aa/Debug.lkf" "Untitled1.c"

Compile Complete,
  0 Errors, 0 Warnings, 0 Remarks.
Will(95367158)  18:09:43

Will(95367158)  18:09:59
这是怎么回事

原创粉丝点击