2012-04-28 5 views
0

행렬을 코딩 중입니다.이 행렬의 요소는 유리한 계수의 다항식입니다. 어떤 도움이라도 대단히 감사하겠습니다. 여기합리적인 다항식 배열에 대한 컴파일 오류

#include "poly_mat.h" 

#define NR_END 1 
#define FREE_ARG char* 

polynomial **poly_matrix(long nrl, long nrh, long ncl, long nch) 
/* allocates a matrix with polynomial entries in the range m[nrl..nrh][ncl..nch] */ 
{ 
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 
    polynomial **m; 
    /* allocate pointers to rows */ 
    m=(polynomial **) malloc((size_t)((nrow+NR_END)*sizeof(polynomial*))); 
    if (!m) nrerror("allocation failure 1 in matrix()"); 
    m += NR_END; 
    m -= nrl; 
    /* allocate rows and set pointers to them */ 
    m[nrl]=(polynomial *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(polynomial))); 
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()"); 
    m[nrl] += NR_END; 
    m[nrl] -= ncl; 
    for (i=nrl+1; i<=nrh; i++) m[i]=m[i-1]+ncol; 
    /* return pointer to array of pointers to rows */ 
    return m; 
} 

void **free_poly_matrix(polynomial **m, long nrl, long nrh, long ncl, long nch) 
/* free a polynomial matrix allocated by poly_matrix() */ 
{ 
    free((FREE_ARG) (m[nrl]+ncl-NR_END)); 
    free((FREE_ARG) (m+nrl-NR_END)); 
} 

void init_random_poly_matrix(int **m, long nrl, long nrh, long ncl, long nch) 
/* initialize a random polynomial matrix with coefficient <=100*/ 
{ 
    long i,j; 
    long iseed = (long)time(NULL); 
    srand (iseed); 
    for (i=nrl; i<=nrh; i++) 
    { 
     for (j=ncl; j<=nch; j++) 
     { 
      m[i][j].degree=(rand()%MAX_DEGREE); 
      for (k=0;k<=MAX_DEGREE;k++) 
      { 
       m[i][j].coef[k].p = (rand()%100); 
       m[i][j].coef[k].q = (1+rand()%100); 
      } 
     } 
    } 
} 

는 수수께끼입니다 전체를
rational_number.h

struct long_rational{ 
    long p; 
    long q; 
    }; 

typedef struct long_rational rational; 

polynomial.h

#define MAX_DEGREE 200 

struct rational_polynomial{ 
    long degree; 
    rational coef[MAX_DEGREE]; //rational coefficients in increase power. 
}; 

typedef struct rational_polynomial polynomial; 

poly_mat.c :
나는 선언 유리수와 합리적인 다항식이 오류 메시지 :

 
gcc -Wall -c -o poly_mat.o poly_mat.c 
poly_mat.c: In function ‘init_random_poly_matrix’: 
poly_mat.c:6: error: expected declaration specifiers before ‘(’ token 
poly_mat.c:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token 
poly_mat.c:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token 
poly_mat.h:14: error: old-style parameter declarations in prototyped function definition 
poly_mat.c:51: error: expected ‘{’ at end of input 
make: *** [poly_mat.o] Error 1 

누락 된 세미콜론이있는 poly_mat.h.

#ifndef POLY_MAT_H 
#define POLY_MAT_H 

#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 
#include "nrutil.h" 
#include "rational_number.h" 
#include "polynomial.h" 

/* matrix with polynomial entries */ 
polynomial **poly_matrix(long nrl, long nrh, long ncl, long nch); 
void init_random_poly_matrix(int **m, long nrl, long nrh, long ncl, long nch); 
void **free_poly_matrix(polynomial **m, long nrl, long nrh, long ncl, long nch); 

#endif 

이제 도트 연산자로 배열의 다항식 멤버에 액세스 할 수 없습니다.
새로운 오류 메시지 :

 
gcc -Wall -c -o poly_mat.o poly_mat.c 
poly_mat.c: In function ‘init_random_poly_matrix’: 
poly_mat.c:43: error: request for member ‘degree’ in something not a structure or union 
poly_mat.c:46: error: request for member ‘coef’ in something not a structure or union 
poly_mat.c:47: error: request for member ‘coef’ in something not a structure or union 
make: *** [poly_mat.o] Error 1 

편집 2 : 실수를 발견. ** 다항식 ** 대신 int **로 선언하십시오.

+0

poly_mat.h에는 어떤 것이 있습니까? –

+0

.cpp 파일에 '다항식'이 표시되어 있습니까? 그리고 실제로 그 시점에서 typedef입니까? –

+0

plz show poly_mat.h –

답변

0

poly_mat.h를 모르더라도, 나는 errormessage를 grok 처리하여 poly_mat.h에 구문 오류가 있음을 알 수 있습니다. init_random_poly_matrix()에 대한 프로토 타입을 선언하는 동안 줄 14 또는 앞뒤에 괄호/중괄호 또는 세미콜론이 누락되어 있다고 생각합니다.

+0

굉장합니다. 헤더 파일을 보지 않고 실수를 탐지합니다. – user103500