多次元行列にスペースを割り当てるときに構文エラーが発生します。私はCでコーディングするのが新しいので、何かが助けになります。このエラーは、read_matrix関数の行列構造要素にアクセスしようとしたときに発生します。構文エラーは、 "式は構造体または共用体型でなければなりません"。エラーが発生した場所はread_matrix関数でコメントアウトされています。Cで関数呼び出しとパラメータを使用してポインタを使用するときの構文エラー
typedef struct {
int *elements;
int rows;
int columns;
} matrix;
void main() {
matrix a, b, c;
void read_matrix(matrix *);
void deallocate(matrix *);
void print(matrix);
matrix add(matrix, matrix);
matrix subtract(matrix, matrix);
matrix multiply(matrix, matrix);
read_matrix(&a);
read_matrix(&b);
c = add(a, b);
deallocate(&c);
c = subtract(a, b);
deallocate(&c);
c = multiply(a, b);
}
void read_matrix(matrix *z) {
int d1, d2, i, x, y, val;
printf("What is the first dimension of the array? ");
scanf("%d", &d1);
printf("What is the second dimension of the array? ");
scanf("%d", &d2);
*z.elements = (int *)calloc(d2, sizeof(int));
*z.rows = d1;
*z.columns = d2;
/* error here. It isn't letting me access the
elements/rows/columns of the matrix */
/* additional code below here */
}
することになって、構文エラーがあるのですか?である必要があり、あなたのケース –
C#のようには見えません...あなたの教科書に書かれている言語の名前を確認してください。 –
@AlexeiLevenkov OPはすでにそれがcだと述べています。無関係なタグを削除しました。 –