error C2143: 语法错误 : 缺少“;”(在“类型”的前面)

C编程老是遇到这个问题:

错误    1    error C2143: 语法错误 : 缺少“;”(在“类型”的前面)    d:\kinectproject\ceshiglad\ceshiglad\shili.c    24    1    ceshiGLAD
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include "data.h"

double Alpha[5]={1,1,1,1,1};
double Beta[10]={1,1,1,1,1,1,1,1,1,1};
double Z1[10]={1,0,1,0,1,0,1,0,1,0};
double labels[150]={0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0};

void main(){
    
    int i,j;
    double *rawPriorBeta = Beta;
    double *rawPriorZ1 = Z1;
    double *rawLabels = labels;
    double *rawPriorAlpha = Alpha;
    Dataset data;
    data.numLabels = 50;
    data.numLabelers = 5;
    data.numImages = 10;
    data.priorZ1 = (double *) malloc(sizeof(double) * data.numImages);
    data.priorAlpha = (double *) malloc(sizeof(double) * data.numLabelers);
    data.priorBeta = (double *) malloc(sizeof(double) * data.numImages);
    
    for (i = 0; i < data.numLabelers; i++) {
        data.priorAlpha[i] = rawPriorAlpha[i];
    }
    
    for (j = 0; j < data.numImages; j++) {
        data.priorBeta[j] = rawPriorBeta[j];
        data.priorZ1[j] = rawPriorZ1[j];
    }

    data.probZ1 = (double *) malloc(sizeof(double) * data.numImages);
    data.probZ0 = (double *) malloc(sizeof(double) * data.numImages);
    data.beta = (double *) malloc(sizeof(double) * data.numImages);
    data.alpha = (double *) malloc(sizeof(double) * data.numLabelers);
    data.labels = (Label *) malloc(sizeof(Label) * data.numLabels);

    
    for (i = 0; i < data.numLabels; i++) {
        /* Remember that Matlab stores data in row-major order! */
        data.labels[i].imageIdx = rawLabels[i];
        data.labels[i].labelerId = rawLabels[data.numLabels + i];
        data.labels[i].label = rawLabels[2 * data.numLabels + i];
    }
}

后来发现,把变量的声明放到main函数的前面,就不会有这个问题了,虽然不知道为什么,但是记一下。

 

posted @ 2014-05-07 11:13  Providence  阅读(2520)  评论(0编辑  收藏  举报