初始化矩阵,预计前$ P在C $ pssion错误 [英] initializing a matrix, expected expression error in C
问题描述
所以我试图查找似乎有帮助,但最终并没有几件事情。
So I have tried looking up a few things that seemed helpful, but ultimately were not.
我应该初始化一个6×8矩阵作为一个独立的功能的二维数组。我有三个文件,主功能文件,一个功能文件,和一个头文件。
I am supposed to initialize a 6x8 matrix as a 2D array in a separate function. I have three files, a main function file, a functions file, and a header file.
下面是相关主要code
Here is relevant code from main
int plate[MAX_ROWS][MAX_COLS];
double A = 0, B = 0, T1 =0, T2 = 0, C = 0;
printf("\n");
printf("Welcome to the Heat Plate Simulation\n\n");
printf("Enter: Heat-A, Heat-B, Plate-1, Plate-2, Stab-Crit\n\n");
scanf("%lf%lf%lf%lf%lf", &A,&B,&T1,&T2,&C);
然后我尝试
initialize_plate(plate,T1, T2);
都到
void initialize_plate(int plate[][MAX_COLS],double T1, double T2)
{
plate[MAX_ROWS][MAX_COLS] = {
{ T1, T1, T1, T2, T2, T2},
{ T1, T1, T1, T2, T2, T2},
{ T1, T1, T1, T2, T2, T2},
{ T2, T2, T2, T1, T1, T1},
{ T2, T2, T2, T1, T1, T1},
{ T2, T2, T2, T1, T1, T1}
};
return;
}
我收到的错误是7P_functions.c:14:32:错误:预期前$之前'{'令牌p $ pssion
*板[MAX_ROWS] [MAX_COLS] = {
The error I receive is 7P_functions.c:14:32: error: expected expression before ‘{’ token *plate[MAX_ROWS][MAX_COLS] = {
鉴于我已经研究这个错误我唯一的猜测是,它是与阵列已经被初始化,但我不知道如何,而如果我初始化函数,而不是在内部数组纠正这个问题主要不只是成为一个局部变量?
Given what I have researched with this error my only guess is that it has something to do with the array already being initialized, but I am not sure how to rectify this problem whereas if I initialize the array within the function and not in main doesn't it just become a local variable?
任何帮助将是非常美联社preciated。
Any help would be much appreciated.
推荐答案
设置使用值的memcpy
从临时数组。
Set the value using memcpy
from the temporary array.
void initialize_plate(int plate[][MAX_COLS],double T1, double T2){
memcpy(plate, (int [][MAX_COLS]){
{ T1, T1, T1, T2, T2, T2},
{ T1, T1, T1, T2, T2, T2},
{ T1, T1, T1, T2, T2, T2},
{ T2, T2, T2, T1, T1, T1},
{ T2, T2, T2, T1, T1, T1},
{ T2, T2, T2, T1, T1, T1} },
6*sizeof(int [MAX_COLS]));
return;
}
这篇关于初始化矩阵,预计前$ P在C $ pssion错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!