#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int row;
int col;
int value;
}Term;
typedef struct
{
int max_row;
int max_col;
int max_term;
int cnt_term;
Term *node;
}S_mat;
S_mat create(int maxRow,int maxCol)
{
S_mat ret;
ret.max_col = maxCol;
ret.max_row = maxRow;
ret.max_term = maxCol * maxRow;
ret.cnt_term = 0;
ret.node = (Term*)malloc(sizeof(Term));
return ret;
}
void insert(S_mat &x, int row, int col, int value)
{
x.cnt_term++;
realloc(x.node,x.cnt_term * sizeof(Term));
x.node[x.cnt_term-1].col = col;
x.node[x.cnt_term-1].row = row;
x.node[x.cnt_term-1].value = value;
}
void Release(S_mat &x)
{
free(x.node);
}
void Display(S_mat &x)
{
int i,j;
for(i=0;i<x.max_col;i++)
{
for(j=0;j<x.max_row;j++)
{
printf(\"%d \",x.term[i][j]);
}
printf(\"\\n\");
}
)
int main(void)
{
S_mat a = create(7,7);
insert(a,6,6,8);
insert(a,0,0,15);
insert(a,0,3,22);
insert(a,3,5,66);
insert(a,2,6,3);
insert(a,5,1,42);
insert(a,3,1,43);
Display(a);
Release(a);
return 0;
}
일케햇는데 오류가
gcc -o out sparse.c
sparse.c:32: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
sparse.c:42: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
sparse.c:47: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
이렇게 뜨네 ㅎㅎ 내가 뭘잘못한겨;; 검색해봐도몰겟고 ㄷㄷ
도와줘여 프갤러들!!
c언어에는 레퍼런스같은거 없다
그니깐 인자는 포인터로 전달해야한다. & 말고 *
우왕 적분기호형감사염
읭? 근데 *로 바꾸니까 또 에러남요 ㅠㅠ
너님 포인터 좀 공부하시죠?