该函数从文件中读取矩阵,并将其打印在屏幕上。但是当库
从 fp 读取文件时出现问题。fscanf(fp, "%u", &elem);
当我更改
为uint8_t elem
.uint8_t *elem
我想知道为什么!程序将 FILE 指针传输到库时应注意什么。谢谢!
主功能:
int main(int argc, char *argv[]){
Matrix8g mat;
FILE *fp;
if((fp = fopen("mat.dat","r")) == NULL){
printf("can't open the file");
}
//matrix with 24 rows and 11 cols
mat.Make_from_file(fp, 24, 11);
//print the matrix
mat.Print();
fclose(fp);
}
部分库文件(Make_from_file):
/* Set the matrix from a file */
int Matrix8g::Make_from_file(FILE *fp, int rows, int cols){
int i, j;
uint8_t elem;
this->rr = rows;
this->cc = cols;
Resize_matrix();
try{
for(i = 0; i < rows; i++){
for(j = 0; j < cols; j++){
fscanf(fp, "%u", &elem);
Set(i, j, elem);
}
}
}catch(...){
NOTE("Error when set the matrix from a file");
return 0;
}
return 1;
}