我正在尝试使矩阵加法运算,但是问题不是加法运算。问题出在字符串中,使用输入命令,我必须检查一切是否正常。对于矩阵加法,我需要获得3个矩阵名称作为输入。
我做了一个算法来查找名称,另一个函数是检查矩阵名称(如果已定义)并保存为“ matInd”。我已经将所有matInd保存在一个数组中。现在我需要调用add_mat函数进行操作,但是add_mat函数必须获取3个参数:double add_mat(double MAT1 [N] [N],double MAT2 [N] [N],double MAT3 [N] [N ])
现在我不知道如何将matInd更改为Matrix名称以调用该函数。
也许我需要另外一种方式吗?
mat.h:
/* Data Structure */
typedef double mat[N][N];
矩阵名称:MAT_A,MAT_B,MAT_C,MAT_D,MAT_E,MAT_F
mymat.c:
/* Declare matrix and initialize to zero */
mat MAT_A = {0}, MAT_B = {0}, MAT_C = {0}, MAT_D = {0}, MAT_E = {0}, MAT_F = {0};
case ADD_MAT:
printf("add mat..\n");
int i = 0;
index = skip_white_char(command, index, commandLen);
if(is_comma(command[index])){
print_error(ILLEGAL_COMMA);
continue;
}
if(command[index]=='\n'){
print_error(MISS_PARAM);
continue;
}
clear_word(nextWord, MAX_WORD_LEN); /* Clear last word from nextWord */
index = get_word(command, nextWord, index);
matInd = which_mat(nextWord); /* Save the index of chosen mat */
if(matInd == UNKNOWN_MAT){
print_error(UNDEF_MAT_NAME);
continue;
}
else {
printf("%d ", matInd);
matrixMan[i++] = matInd;
}
while(is_comma(command[index])){
index++;
index = skip_white_char(command, index, commandLen);
if(is_comma(command[index])){
print_error(ILLEGAL_COMMA);
continue;
}
if(command[index]=='\n'){
print_error(MISS_PARAM);
continue;
}
clear_word(nextWord, MAX_WORD_LEN); /* Clear last word from nextWord */
index = get_word(command, nextWord, index);
matInd = which_mat(nextWord); /* Save the index of chosen mat */
if(matInd == UNKNOWN_MAT){
print_error(UNDEF_MAT_NAME);
continue;
}
else {
matrixMan[i++] = matInd;
}
index = skip_white_char(command, index, commandLen);
}
if(command[index]!='\n'){ /* There is parameters without comma between */
return MISS_COMMA;
}
continue;