读书人

稀疏矩阵有关问题编译出错启动不了

发布时间: 2012-04-28 11:49:53 作者: rapoo

稀疏矩阵问题,编译出错,启动不了调试!
TribleMatrix.h文件:
#ifndef TRIBLE_MATRIX_H
#define TRIBLE_MATRIX_H

#define MAX_SIZE 500;
typedef int ElemType;

typedef struct
{
int i,//The row coordinate
j;//The column coodinate
ElemType elem; //The value of non-zero element.
}Triple; //End the definition of the triple

typedef struct
{
Triple data[MAX_SIZE+1]; //data[0] is unused.
int rows, //The rows of the matrix
cols, //The columns of the matirx
notZeros; // The numbers of non-zero elements.
}SparseMatrix;
#endif


main.c文件:
#include <stdio.h>
#include "TribleMatrix.h"

int main()
{
SparseMatrix spaMatrix;
int x, y;

spaMatrix.data[1].i = 1;
spaMatrix.data[1].j = 1;
spaMatrix.data[1].elem = 1;

spaMatrix.data[2].i = 1;
spaMatrix.data[2].j = 3;
spaMatrix.data[2].elem =3;

spaMatrix.data[3].i = 2;
spaMatrix.data[3].j = 3;
spaMatrix.data[3].elem = 1;

spaMatrix.notZeros = 3;
spaMatrix.cols = 3;
spaMatrix.rows = 3;

printf("The current sparse matrix is :\n");
printf("i\tj\tv\n");
for (x = 1; x <= spaMatrix.rows; x++)
{
for (y = 1; y <= spaMatrix.cols; y++)
{
printf("%d\t%d\t%d\n", spaMatrix.data[x].i,
spaMatrix.data[x].j, spaMatrix.data[x].elem);
}
}
}



提示的错误:
1>正在编译...
1>main.c
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\triblematrix.h(16) : error C2143: syntax error : missing ']' before ';'
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\triblematrix.h(16) : error C2059: syntax error : '+'
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\triblematrix.h(20) : error C2059: syntax error : '}'
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(6) : error C2065: 'SparseMatrix' : undeclared identifier
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(6) : error C2146: syntax error : missing ';' before identifier 'spaMatrix'
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(6) : error C2065: 'spaMatrix' : undeclared identifier
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(7) : error C2143: syntax error : missing ';' before 'type'
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(9) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(10) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(11) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(13) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(14) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(15) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(17) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(18) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(19) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(21) : error C2224: left of '.notZeros' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(22) : error C2224: left of '.cols' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(23) : error C2224: left of '.rows' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(27) : error C2065: 'x' : undeclared identifier
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(27) : error C2224: left of '.rows' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(28) : error C2065: 'y' : undeclared identifier
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(28) : error C2224: left of '.cols' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(30) : error C2224: left of '.data' must have struct/union type


1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(31) : error C2224: left of '.data' must have struct/union type
1>g:\c++学习\我的c++程序\稀疏矩阵\稀疏矩阵\main.c(31) : error C2224: left of '.data' must have struct/union type
1>生成日志保存在“file://g:\C++学习\我的C++程序\稀疏矩阵\稀疏矩阵\Debug\BuildLog.htm”
1>稀疏矩阵 - 26 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========



[解决办法]
#define MAX_SIZE 500;
多了个分号.改为
==>
#define MAX_SIZE 500

读书人网 >C++

热点推荐